Generic casters for composite types - Mailing list psycopg

From Ronan Dunklau
Subject Generic casters for composite types
Date
Msg-id 4EEA0F7F.9030701@gmail.com
Whole thread Raw
Responses Re: Generic casters for composite types  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
List psycopg
Hello.

I think it may be interesting to add a generic mechanism for registering
composite type casters.

One of the features I like about postgresql is the ability to perform
queries like this one:

select user_group, array_agg(user) from user_group natural join user
group by user_group

Where user_group and user are two tables related by a foreign key.

Such a query is pleasant to write, but unusable for now because psycopg
returns those values as strings.

Since those types are defined by postgresql at table creation time, it
should be easy to parse those results to return namedtuples.

Would you find a such a feature interesting ? Or is it something that
should be best kept in a distinct library ?

I've attached a small 'proof of concept' file demonstrating how this
could be implemented. The parser implementation is simplistic (and does
not work with complex types), but if this is of interest to you I would
happily work on it.

--
Ronan Dunklau


Attachment

psycopg by date:

Previous
From: Federico Di Gregorio
Date:
Subject: Re: [snafu] isolation-level change in 2.4.2
Next
From: Daniele Varrazzo
Date:
Subject: Re: Generic casters for composite types