This project is archived and is in readonly mode.

#66 ✓resolved
Sergey Shepelev

Array of composite/hstore type

Reported by Sergey Shepelev | August 15th, 2011 @ 03:05 PM

db=> create type comp_type_test as (id uuid, f1 char(2), f2 smallint, f3 char(3), f4 char(3));

>>> psycopg2.extras.register_composite('comp_type_test', connection, globally=True)

>>> db.execute("select ('000003b3-50a9-eeaa-4aab-2a95e6ca6592', 'J2', 600, 'MOW', 'BER')::comp_type_test").fetchone()
(comp_type_test(id=UUID('000003b3-50a9-eeaa-4aab-2a95e6ca6592'), f1=u'J2', f2=600, f3=u'MOW', f4=u'BER'),)

This is good.

>>> db.execute("select array[('000003b3-50a9-eeaa-4aab-2a95e6ca6592', 'J2', 600, 'MOW', 'BER')]::comp_type_test[]").fetchone()
('{"(000003b3-50a9-eeaa-4aab-2a95e6ca6592,J2,600,MOW,BER)"}',)

This is not good.

Is it possible to make psycopg2 understand arrays of composite values (or at least arrays of hstore)?

Comments and changes to this ticket

  • Daniele Varrazzo

    Daniele Varrazzo August 22nd, 2011 @ 03:48 PM

    • State changed from “new” to “open”
    • Tag set to array, hstore

    Array of hstores are not supported yet. Shouldn't be terribly hard to introduce them though.

    Do you want to give it a try? Otherwise I could try to make it, but can't guarantee it would be in for next release - 2.4.3.

  • Daniele Varrazzo

    Daniele Varrazzo September 22nd, 2011 @ 06:03 PM

    • State changed from “open” to “resolved”

    Added hstore/composite (and generic) array support to my devel branch.

    To be released in 2.4.3.

  • Paul Eipper

    Paul Eipper July 3rd, 2013 @ 05:10 PM

    This is great, we just needed to patch it to cast values to string before doing the getquoted call on the array items:

    values = [str(v) for v in self.wrapped.values()]
    
  • Paul Eipper

    Paul Eipper July 3rd, 2013 @ 05:12 PM

    Sorry, the above comment should be in regard to issue #2

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

Tags

Pages