Re: Rows from a stored procedure result are stringified
От | Christopher David Howie |
---|---|
Тема | Re: Rows from a stored procedure result are stringified |
Дата | |
Msg-id | 4EF247A1.7000906@chrishowie.com обсуждение исходный текст |
Ответ на | Re: Rows from a stored procedure result are stringified (Daniele Varrazzo <daniele.varrazzo@gmail.com>) |
Ответы |
Re: Rows from a stored procedure result are stringified
|
Список | psycopg |
On 12/21/2011 03:14 PM, Daniele Varrazzo wrote: >> 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>. Hmm. This makes sense to some degree. I do note that strings coming back from the database are not quoted. Is there a parsing routine in psycopg that I can leverage to turn this kind of database-provided tuple-as-a-string representation into a proper tuple/list? -- Chris Howie http://www.chrishowie.com http://en.wikipedia.org/wiki/User:Crazycomputers If you correspond with me on a regular basis, please read this document: http://www.chrishowie.com/email-preferences/ PGP fingerprint: 2B7A B280 8B12 21CC 260A DF65 6FCE 505A CF83 38F5 ------------------------------------------------------------------------ IMPORTANT INFORMATION/DISCLAIMER This document should be read only by those persons to whom it is addressed. If you have received this message it was obviously addressed to you and therefore you can read it. Additionally, by sending an email to ANY of my addresses or to ANY mailing lists to which I am subscribed, whether intentionally or accidentally, you are agreeing that I am "the intended recipient," and that I may do whatever I wish with the contents of any message received from you, unless a pre-existing agreement prohibits me from so doing. This overrides any disclaimer or statement of confidentiality that may be included on your message.
В списке psycopg по дате отправления: