Re: Custom array types converter

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Ronan Dunklau <ronan(dot)dunklau(at)kozea(dot)fr>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: Custom array types converter
Date: 2011-07-01 15:17:58
Message-ID: BANLkTiny9CvOXAid0OP448PZ4oA=yj4Acw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On Fri, Jul 1, 2011 at 2:05 PM, Ronan Dunklau <ronan(dot)dunklau(at)kozea(dot)fr> wrote:
> Hello.
>
> I'd like to register a type converter for _record (array of records).
>
> What is the "recommended" way to implement such a type ?

Psycopg doesn't play well with the generic record, as it has no type
information to parse the components. It can map user-defined types
though, as these informations are available in the catalog. However
there's currently no support for arrays of composite.

> I've seen that a "GENERIC_ARRAY" type caster is available in the c library,
> but I don't know how to access it from python.

I don't know the code in typecast_array.c very well, but if it can
tokenize the array string representation and delegate parsing of the
single items to another typecaster it should be easy to create the
missing array casters (composite array, hstore array...).

I think the code for the generic array casting is currently not
exposed to python. Probably a good extension could be to add an
optional array_oids parameter to the new_type() function in order to
register the arrays together with the base type
(http://initd.org/psycopg/docs/extensions.html#database-types-casting-functions).

-- Daniele

In response to

Browse psycopg by date

  From Date Subject
Next Message deavid 2011-07-05 07:07:47 Named Cursors WITH HOLD
Previous Message Ronan Dunklau 2011-07-01 13:05:44 Custom array types converter