Обсуждение: Custom array types converter

Поиск
Список
Период
Сортировка

Custom array types converter

От
Ronan Dunklau
Дата:
Hello.

I'd like to register a type converter for _record (array of records).

What is the "recommended" way to implement such a type ?

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.

(disclaimer : I am a newbie in both psycopg2, and using native (C) code in
python).

Thanks.

--
Ronan Dunklau

Re: Custom array types converter

От
Daniele Varrazzo
Дата:
On Fri, Jul 1, 2011 at 2:05 PM, Ronan Dunklau <ronan.dunklau@kozea.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