From: | Ronan Dunklau <rdunklau(at)gmail(dot)com> |
---|---|
To: | psycopg(at)postgresql(dot)org |
Subject: | Generic casters for composite types |
Date: | 2011-12-15 15:17:19 |
Message-ID: | 4EEA0F7F.9030701@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 | Content-Type | Size |
---|---|---|
tabletypes.py | text/x-python | 1.6 KB |
test.py | text/x-python | 1.9 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Daniele Varrazzo | 2011-12-15 16:21:30 | Re: Generic casters for composite types |
Previous Message | Federico Di Gregorio | 2011-12-15 13:01:02 | Re: [snafu] isolation-level change in 2.4.2 |