You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I perform a query that returns an array (possibly only if it's of a datatype that doesn't have a native python conversion and so is represented as a string), then empty arrays are (correctly) returned as empty lists, but nonempty arrays are (incorrectly) returned as a single string in postgres array syntax.
What I think should happen is that any column of an ARRAY type should always return a list (or None for NULL), and the list elements should be whatever they would be if they were returned as individual objects.
For example, here's what happens if I select from a simple "hosts" table:
>>> cu.execute("select address from hosts") ; cu.fetchall()
[([],), ('{10.1.0.1}',), ('{192.168.2.1,192.168.2.2}',)]
Notice that the value is a python list for the empty array row, but is a python string for the non-empty array rows.
In contrast, the psycopg2 module returns the values I expect:
If I perform a query that returns an array (possibly only if it's of a datatype that doesn't have a native python conversion and so is represented as a string), then empty arrays are (correctly) returned as empty lists, but nonempty arrays are (incorrectly) returned as a single string in postgres array syntax.
What I think should happen is that any column of an ARRAY type should always return a list (or None for NULL), and the list elements should be whatever they would be if they were returned as individual objects.
For example, here's what happens if I select from a simple "hosts" table:
Notice that the value is a python list for the empty array row, but is a python string for the non-empty array rows.
In contrast, the psycopg2 module returns the values I expect:
(On the other hand if I have a column of type
TEXT ARRAY
orINTEGER ARRAY
, then I get the behavior I expect.)The database table was created as:
Versions: psycopg2cffi 2.7.7, postgres 10.1, psycopg2 2.7.3.2, python 3.6.3
The text was updated successfully, but these errors were encountered: