Re: Accessing complex types

Michael Hipp <[email protected]> Fri, 29 Apr 2005 09:18:28 -0500
Newsgroups gmane.comp.python.db.pypgsql.user
Message-ID <[email protected]>
Billy G. Allie wrote:
> On Mon, 2005-04-25 at 13:42 -0500, Michael Hipp wrote:
> 
>>I'm really hoping someone can tell me I'm doing something wrong ...
>>
>>I have a table that has a complex (user defined) type like this:
>>
>>CREATE TYPE addr_phone AS (
>>    addr1 character varying(40),
>>    addr2 character varying(40),
>>    city character varying(40),
>>    state character(2),
>>    zip character(5),
>>    phone character(12))
[snip]
> pyPgSQL doesn't know about user created types.  You would need to create 
> a python type that represents yoour created type and then instantiate an 
> object of that type passing it the string returned by the query.  (HINT: 
> if your python type has a _quote() function, then pyPgSQL will use it to 
> quote the value when it is used in a query).  Right now, integrating 
> that type into pyPgSQL is not easy, but can be done.  pyPgSQL version 3 
> will have a way to register user defined types so that pyPgSQL will do 
> the right thing with it.

Thank you.

If I comprehend the explanation, the bottom line is that I must parse 
that raw string in order to get the data out of it. Creating a matching 
python type hides those machinations from the rest of the program but 
the gory work must still be done.

Correct?

Michael



-------------------------------------------------------
SF.Net email is sponsored by: Tell us your software development plans!
Take this survey and enter to win a one-year sub to SourceForge.net
Plus IDC's 2005 look-ahead and a copy of this survey
Click here to start!  http://www.idcswdc.com/cgi-bin/survey?id=105hix