Thread: Hstore array implementation.
Hello.
I have implemented an Hstore array type converter for psycopg2.
I thought it may be of interest to you, even if I'm afraid I may have forgotten things in my implementation.
You can look at the patch here:
Regards,
--
Ronan Dunklau
On Thu, Oct 6, 2011 at 8:00 AM, Ronan Dunklau <rdunklau@gmail.com> wrote: > Hello. > I have implemented an Hstore array type converter for psycopg2. > I thought it may be of interest to you, even if I'm afraid I may have > forgotten things in my implementation. > You can look at the patch here: > https://github.com/Kozea/psycopg/commit/60fd7ecf833f1e56a41cca7b5700dea2add75091 Hi Ronan, thank you for the effort. But I've already added generic array support for psycopg. Or, better, the support was there, but was available only in C and was not exposed to Python. I've added the function new_array_type(), which is similar to new_type: it takes a type caster for a single item and a list of oids and creates a new type caster to parse array of the same types: see <http://initd.org/psycopg/docs/extensions.html#database-types-casting-functions>. With this extension, now hstore and composite types casters support arrays too. I think fog hasn't reviewed these patched yet so things are not set in stone, but exposing the internal array handling system to python seems a good idea. They should be released in the upcoming 2.4.3. I'm sorry for having had your time wasted: we had a ticket open on the feature (http://psycopg.lighthouseapp.com/projects/62710/tickets/66) and I'd closed it two weeks ago. I was probably not enough as communication (but then, I don't know if you approached the problem because you found the ticket or you needed it for yourself). Thank you anyway! -- Daniele
On 06/10/11 09:00, Ronan Dunklau wrote: > Hello. > > I have implemented an Hstore array type converter for psycopg2. > > I thought it may be of interest to you, even if I'm afraid I may have > forgotten things in my implementation. Hi Ronan, thank you very much for the patch. You'll probably want to refactor it a little bit after next release that will add generic array support (written by Daniele). federico -- Federico Di Gregorio fog@initd.org Beh un bacio, se ben dato, non si rifiuta. -- <laura>
On Thu, Oct 6, 2011 at 8:51 AM, Federico Di Gregorio <fog@dndg.it> wrote: [ sorry fog: your message was in moderation: you were not using the usual email address. I've added it to the list - nopost] -- Daniele
Sorry, I didn't see the bug report: last time I tried to access the bug tracker it was down.
Don't be sorry, it did not take much time to implement, and I needed it right now.
Generic array support is great !
I've been waiting for it since a while (hstore arrays, record arrays...)
Is your devel branch available publicly ?
I tried to look at the devel branch from git://luna.dndg.it/public/psycopg2.git, and did not find anything regarding that.
Regarding new_type, does it automatically register an array type for every type, or does the developer have to manually register the type and array type ?
Thanks for the good work !
--
Ronan Dunklau
2011/10/6 Daniele Varrazzo <daniele.varrazzo@gmail.com>
Hi Ronan,On Thu, Oct 6, 2011 at 8:00 AM, Ronan Dunklau <rdunklau@gmail.com> wrote:
> Hello.
> I have implemented an Hstore array type converter for psycopg2.
> I thought it may be of interest to you, even if I'm afraid I may have
> forgotten things in my implementation.
> You can look at the patch here:
> https://github.com/Kozea/psycopg/commit/60fd7ecf833f1e56a41cca7b5700dea2add75091
thank you for the effort. But I've already added generic array support
for psycopg. Or, better, the support was there, but was available only
in C and was not exposed to Python.
I've added the function new_array_type(), which is similar to
new_type: it takes a type caster for a single item and a list of oids
and creates a new type caster to parse array of the same types: see
<http://initd.org/psycopg/docs/extensions.html#database-types-casting-functions>.
With this extension, now hstore and composite types casters support
arrays too. I think fog hasn't reviewed these patched yet so things
are not set in stone, but exposing the internal array handling system
to python seems a good idea. They should be released in the upcoming
2.4.3.
I'm sorry for having had your time wasted: we had a ticket open on the
feature (http://psycopg.lighthouseapp.com/projects/62710/tickets/66)
and I'd closed it two weeks ago. I was probably not enough as
communication (but then, I don't know if you approached the problem
because you found the ticket or you needed it for yourself).
Thank you anyway!
-- Daniele
On Thu, Oct 6, 2011 at 12:06 PM, Ronan Dunklau <rdunklau@gmail.com> wrote: > Sorry, I didn't see the bug report: last time I tried to access the bug > tracker it was down. > Don't be sorry, it did not take much time to implement, and I needed it > right now. > Generic array support is great ! Yes, it's neat, and it's the way all builtin array casters are implemented. it's been buried in the C code since ever, it just had to surface :) > I've been waiting for it since a while (hstore arrays, record arrays...) > Is your devel branch available publicly ? It is in the devel branch of my clone, at <https://github.com/dvarrazzo/psycopg/>, see commits of Sep 22. > I tried to look at the devel branch from > git://luna.dndg.it/public/psycopg2.git, and did not find anything regarding > that. > Regarding new_type, does it automatically register an array type for every > type, or does the developer have to manually register the type and array > type ? Registration has to be separate: for instance register_hstore() hast something like that in its implementation: HSTORE = _ext.new_type(oid, "HSTORE", cast) _ext.register_type(HSTORE, [where]) HSTOREARRAY = _ext.new_array_type(array_oid, "HSTOREARRAY", HSTORE) _ext.register_type(HSTOREARRAY, [where]) The hstore/composite casters think themselves to register the array casters too; authors of new typecasters should do themselves in a similar way. > Thanks for the good work ! Cheers :)