This project is archived and is in readonly mode.
ARRAY could not convert type double precision[] to numeric[]
-
Daniele Varrazzo
Cannot reproduce the issue: adaptation seems performed ok. What is the definition of the table?
With the lack of such definition I can only try a cast, and it seems working fine:
In [6]: cur.execute("select %s::numeric[]", [values]) In [7]: cur.fetchone() Out[7]: ([[[Decimal('0.0'), Decimal('2.0')], [Decimal('NaN'), Decimal('1.0')], [Decimal('0.0'), Decimal('0.0')]]],) In [8]: cur.execute("select %s::double precision[]", [values]) In [9]: cur.fetchone() Out[9]: ([[[0.0, 2.0], [nan, 1.0], [0.0, 0.0]]],)Please post the definition of the table and the postgres version you are using. I suspect it is a Postgres limitation, not a psycopg one. psycopg version tested is 2.4.2 (can't remember about any fix performed between 2.4.0 and 2.4.2 that could influence this result).
-
Oscar Martinez
Hi,
Sorry for the lack of info. I post now the definition of the table. I have asked the admin to update the psycopg2 to the last one (2.4.2) but I still get the same error. BTW, teh postgres version is 8.1.22
In [1]: import psycopg2 In [2]: connection = psycopg2.connect("dbname='martinez' user='postgres' host='node079'") In [3]: cursor = connection.cursor() In [4]: cursor.execute('CREATE TABLE PROBA (col DOUBLE PRECISION[][][])') In [5]: connection.commit() In [6]: values = [[[0.,2.],[0.,1.],[0.,0.]],] In [7]: cursor.execute('INSERT INTO PROBA (col) VALUES (%s)', [values,]) In [8]: values = [[[0.,2.],[float('NaN'),1.],[0.,0.]],] In [9]: cursor.execute('INSERT INTO PROBA (col) VALUES (%s)', [values,]) --------------------------------------------------------------------------- ProgrammingError Traceback (most recent call last) /home/users/martinez/<ipython console> in <module>() ProgrammingError: ARRAY could not convert type double precision[] to numeric[] In [10]: psycopg2.__version__ Out[10]: '2.4.2 (dt dec pq3 ext)'Thanks
-
Daniele Varrazzo
Your problem is in postgres: probably 8.1 doesn't support NaN in numeric array. Your test works fine with postgres 9.0.
-
Oscar Martinez
Ok, I will ask the admin to upgrade it
Thanks very much! -
Daniele Varrazzo
- State changed from new to invalid
I've tested with my collection of dbs and you need at least PostgreSQL 8.4.