pl/python custom datatype parsers
От | Jan Urbański |
---|---|
Тема | pl/python custom datatype parsers |
Дата | |
Msg-id | 4D13596C.3020204@wulczer.org обсуждение исходный текст |
Ответы |
Re: pl/python custom datatype parsers
|
Список | pgsql-hackers |
Here's a patch implementing custom parsers for data types mentioned in http://archives.postgresql.org/pgsql-hackers/2010-12/msg01991.php. It's an incremental patch on top of the plpython-refactor patch sent eariler. Git branch for this patch: https://github.com/wulczer/postgres/tree/custom-parsers. The idea has been discussed in http://archives.postgresql.org/pgsql-hackers/2010-12/msg01307.php. With that patch, when built with --with-python, the hstore module includes code that adds a GUC called plpython.hstore. This GUC should be set to the full name of the hstore datatype, for instance plpython.hstore = 'public.hstore'. If it is set, the datatype's OID is looked up and hstore sets up a rendezvous variable called PLPYTHON_<OID>_PARSERS that points to two functions that can convert a hstore Datum to a PyObject and back. PL/Python ot the other hand when it sees an argument with an unknown type tries to look up a rendezvous variable using the type's OID and if it finds it, it uses the parser functions pointed at by that variable. Long story short, it works so: LOAD 'hstore'; SET plpython.hstore = 'public.hstore' CREATE FUNCTION pick_one(h hstore, key text) RETURNS hstore AS $$ return {key: h[key]} $$ LANGUAGE plpythonu; SELECT pick_one('a=>3,b=>4', 'b') -- gives bask a hstore 'b=>4' There's some ugliness with how hstore's Makefile handles building it, and I'm not sure what's needed to make it work with the Windows build system. Also, documentation is missing. It's already usable, but if we decide to commit that, I'll probably need some help with Windows and docs. I first tried to make hstore generate a separate .so with that functionality if --with-python was specified, but couldn't convince the Makefile to do that. So if you configure the tree with --with-python, hstore will link to libpython, maybe that's OK? Cheers, Jan PS: of course, once committed we can add custom parsers for isbn, citext, uuids, cubes, and other weird things. J
Вложения
В списке pgsql-hackers по дате отправления: