Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

Array of composite/hstore type

#66
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)?

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

State: resolved
Milestone: none
Assigned to: nobody

Activity

  1. Daniele Varrazzo
    Daniele Varrazzo
    • 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.

    August 22nd, 2011 @ 03:48 PM

  2. Daniele Varrazzo
    Daniele Varrazzo
    • State changed from open to resolved

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

    To be released in 2.4.3.

    September 22nd, 2011 @ 06:03 PM

  3. Paul Eipper
    Paul Eipper

    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()]
    

    July 3rd, 2013 @ 05:10 PM

  4. Paul Eipper
    Paul Eipper

    Sorry, the above comment should be in regard to issue #2 dict-hstore adaptation

    July 3rd, 2013 @ 05:12 PM