首页 \ 问答 \ 设置ArrayList的ArrayList的初始容量(Set the initial capacity of ArrayList of ArrayLists)

设置ArrayList的ArrayList的初始容量(Set the initial capacity of ArrayList of ArrayLists)

我有ArrayList的ArrayList。 我想设置内部ArrayLists的初始容量以及外部ArrayList,但不一定要达到相同的大小。 有没有一个好的方法来做到这一点?


I have an ArrayList of ArrayLists. I would like to set the initial capacity of the inner ArrayLists as well as the outer ArrayList, though not necessarily to the same size. Is there a good way to do this?


原文:https://stackoverflow.com/questions/24703448
更新时间:2022-03-20 22:03

最满意答案

您需要将这些数组转换为类型,因为postgres不知道如何将记录中的复合类型与列定义列表相匹配。

CREATE TYPE f AS (col1 text, col2 real, col3 real, col4 int);

SELECT * FROM
UNNEST(
  ARRAY[('1234jc', 0.0, 1.2123, 1), ('1234sc', 1.0, 1.74, 1)] :: f[]
);

在Python中

query = """ CREATE TYPE f AS (id text, result real, result1 real, result2 int); 
            INSERT INTO test.result_data

            SELECT id,
                   result,
                   result1,
                   result2
            FROM unnest(%s :: f[])
            AS s(id text, result real, result1 real, result2 integer)
"""

You need to cast those arrays to a type because postgres don't know how to match the composite type in your records to the column definition list.

CREATE TYPE f AS (col1 text, col2 real, col3 real, col4 int);

SELECT * FROM
UNNEST(
  ARRAY[('1234jc', 0.0, 1.2123, 1), ('1234sc', 1.0, 1.74, 1)] :: f[]
);

In Python

query = """ CREATE TYPE f AS (id text, result real, result1 real, result2 int); 
            INSERT INTO test.result_data

            SELECT id,
                   result,
                   result1,
                   result2
            FROM unnest(%s :: f[])
            AS s(id text, result real, result1 real, result2 integer)
"""

相关问答

更多
  • 需要使用python-dev软件包来编译C或C ++编写的Python扩展,如psycopg2 。 如果您运行的是基于Debian的发行版(例如Ubuntu),则可以通过运行安装python-dev apt-get install python-dev 要么 apt-get install python3-dev 取决于你的python版本。 之后,像往常一样在你的virtualenv环境中安装psycopg2 。 The python-dev package is required for compi ...
  • Craig Ringer给出了正确的答案,我只是添加了这个,因为我知道我们应该首先检查我们系统上安装的64位或32位Python版本。 如果你有32位版本的Python,如果你试图安装64位,那么你将在导入时遇到上述错误。 用于检查版本: import platform platform.architecture() 你会得到这样的输出: ('32bit','WindowsPE') The correct answer was given by Craig Ringer, I am just adding ...
  • 我已经解决了。 将gcc升级到4.8.2完成了工作。 不管怎么说,还是要谢谢你。 I've already solved it. Upgrading gcc to 4.8.2 did the work. Thanks anyway.
  • 您需要将这些数组转换为类型,因为postgres不知道如何将记录中的复合类型与列定义列表相匹配。 CREATE TYPE f AS (col1 text, col2 real, col3 real, col4 int); SELECT * FROM UNNEST( ARRAY[('1234jc', 0.0, 1.2123, 1), ('1234sc', 1.0, 1.74, 1)] :: f[] ); 在Python中 query = """ CREATE TYPE f AS (id text, r ...
  • 如果您拥有psycopg2包含的C代码,那么仅仅复制python文件将无效。 作为解决方法,您可以使用pure-python pg8000或: 使用virtualenv env创建virtualenv env 。 在所说的virtualenv中安装psycopg2 - env/bin/pip install psycopg2 。 生成requirements.txt - env/bin/pip freeze > requirements.txt 将requirements.txt复制到部署服务器,如果您正在 ...
  • 所以问题是因为我使用的是pypy-5.3.1运行时。 我将其更改为python-2.7.13并且它可以工作。 So the problem was because i was using the pypy-5.3.1 runtime. I changed this to python-2.7.13 and it works.
  • 我遇到了同样的问题,就是psycopg2在Windows中没有安装_easy_install_,我按照以下SO回答的说明操作: 在windows上的virtualenv中安装psycopg2(postgresql) 您需要手动安装psycopg2 exe文件: psycopg2-2.4.2.win-AMD64-py2.7-pg9.0.4-release.exe I had the same problem, it was that psycopg2 does not install well in Wind ...
  • 你需要安装以下依赖项sudo apt-get install python-dev libxml2-dev libxslt1-dev zlib1g-dev You need to install the following dependencies sudo apt-get install python-dev libxml2-dev libxslt1-dev zlib1g-dev
  • 除非您对使用本机postgresql库有严格要求,否则我建议您使用pg8000库,因为这是纯Python。 自从我几年前发现它以来,我就停止使用另一个,忘记了必须在很多平台上编译它。 Unless you do have a hard requirement on using the native postgresql library, I would advise you to use the pg8000 library instead because this one is pure python. ...
  • 在安装软件包时, 不要尝试混合体系结构,因为许多机器都会因为多个环境而中断。 ELF头定义了要使用的架构(即64位或32位)等。因此,安装Linux版本应该很好。 You must not try to mix architectures whilst installing packages, as many tend to break due to multiple environments on one machine. ELF headers define which architecture to ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)