This project is archived and is in readonly mode.

#181 ✓invalid
Dave Rawks

Arrays of INET type not properly parsed into a list

Reported by Dave Rawks | September 26th, 2013 @ 10:06 PM

An array of INET is returned as an unparsed string while and array of TEXT is parsed correctly and returned as a list of strings.
I tested on 2.5.1 and 2.4.6 and got the same result.

import psycopg2 conn = psycopg2.connect(host='test', database='schema_test_3') cur = conn.cursor() cur.execute("SELECT ips from hardware LIMIT 20;") cur.next()

('{127.0.0.1,10.10.1.16}',)

cur.execute("SELECT roles from hardware LIMIT 20;") cur.next()

(['ALLHOSTS', 'DEBIANHOSTS'],)

Comments and changes to this ticket

  • Daniele Varrazzo

    Daniele Varrazzo October 21st, 2013 @ 02:13 PM

    • State changed from “new” to “invalid”

    Please follow the new_array_type example to see how to create a generic array type caster.

    >>> cur.execute("select '{127.0.0.1,10.10.1.16}'::inet[]")
    >>> print cur.fetchone()
    ('{127.0.0.1,10.10.1.16}',)
    
    >>> cur.execute("select typarray from pg_type where typname = 'inet'")
    >>> print cur.fetchone()
    (1041,)
    
    >>> psycopg2.extensions.register_type(
    ...     psycopg2.extensions.new_array_type(
    ...         (1041,), 'INET[]', psycopg2.STRING))
    
    >>> cur.execute("select '{127.0.0.1,10.10.1.16}'::inet[]")
    >>> print cur.fetchone()
    (['127.0.0.1', '10.10.1.16'],)
    

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

<b>WARNING:</b> the informations in this tracker are archived. Please submit new tickets or comments to <a href="https://github.com/psycopg/psycopg2/issues">the new tracker</a>.
<br/>
Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.

Shared Ticket Bins

Pages