Re: Rows from a stored procedure result are stringified - Mailing list psycopg

From Daniele Varrazzo
Subject Re: Rows from a stored procedure result are stringified
Date
Msg-id CA+mi_8Z8afOvEOH4ObtqYuZGwrwoVbAS61b9iS82q8kefO6cKQ@mail.gmail.com
Whole thread Raw
In response to Rows from a stored procedure result are stringified  (Christopher David Howie <me@chrishowie.com>)
Responses Re: Rows from a stored procedure result are stringified  (Christopher David Howie <me@chrishowie.com>)
List psycopg


On Dec 21, 2011 8:52 PM, "Christopher David Howie" <me@chrishowie.com> wrote:
>
> I'm working on an application using psycopg2 2.2.1.  Regarding stored
> procedures, I'm seeing some odd behavior.  I am calling the procedure like:
>
> SELECT sp_foobar(1, 2, 3);
>
> In this case, the stored procedure is declared to return a "setof" a
> custom type, and it returns using "RETURN QUERY SELECT ...".
>
> I would expect the rows to come back from cursor.fetchall() in this
> structure:
>
> [(1,2),(3,4),(5,6)]
>
> But they are returned like this:
>
> [('(1,2)'),('(3,4)'),('(5,6)')]
>
> This makes no sense to me.  Is this expected/documented behavior?

Yes: it is expected: if psycopg finds a type it doesn't know, it will just return the string passed by the database. Doesn't it make sense? :-)

You can extend psycopg adding your custom type using register_composite(): see < http://initd.org/psycopg/docs/extras.html#composite-types-casting>. It requires psycopg 2.4 though. Alternatively you can write and register your own type parser: see  <http://initd.org/psycopg/docs/advanced.html#type-casting-of-sql-types-into-python-objects>.

-- Daniele

psycopg by date:

Previous
From: Christopher David Howie
Date:
Subject: Rows from a stored procedure result are stringified
Next
From: Christopher David Howie
Date:
Subject: Re: Rows from a stored procedure result are stringified