设置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) """
相关问答
更多-
尝试安装Postgres for python(psycopg2)时出错(Error trying to install Postgres for python (psycopg2))[2022-05-19]
需要使用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的模块(No module named psycopg2)[2022-10-10]
我遇到了同样的问题,就是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 ...