Re: hstores in pl/python - Mailing list pgsql-hackers

From Jan Urbański
Subject Re: hstores in pl/python
Date
Msg-id 20101215110944.GA17954@wulczer.org
Whole thread Raw
In response to Re: hstores in pl/python  (Jan Urbański <wulczer@wulczer.org>)
Responses Re: hstores in pl/python  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Wed, Dec 15, 2010 at 12:19:53AM +0100, Jan Urbański wrote:
> Problem: what to do it hstore_plpython gets loaded, but hstore is not
> yet loaded. hstore_plpython will want to DirectFunctionCall(hstore_in),
> so loading hstore_plpython without loading hstore will result in an
> ereport(ERROR, "undefined symbol hstore_in") with an errhint of "please
> load hstore first". I could live with that, if no one has a better idea.

Correction: you won't get the helpful errhint, because the ERROR will be thrown when some does LOAD. And it still does
notsolve the problem of knowing whether it's a hstore that's been passed in to you.
 

OK, here's another master plan:

1) hstore_plplython, when loaded, looks for a type called "hstore". If you created a "hstore" type that does not come
fromhstore.so, and you still load hstore_plpython, you deserve a segfault. If there is no type "hstore", it throws an
ERROR.If it finds a type with that name, it creates a rendezvous variable with the name OID_plpython_parsers that
pointsto two functions. These functions use the looked up type's I/O funcs and transform things you pass to them from
andinto Python objects.
 

2) plpython, when receiving an object with a type with the name X, takes its OID, it the OID happens not to be one of
BOOLOID,FLOAT8OID etc, it does one last push of looking for a rendezvous variable OID_plpython_parsers and if it finds
one,uses its parsers. If it doesn't find it, it does what it did now (cast to text and pass it to the type's I/O
func).

That looks almost good to me. It's mildly annoying that you can't load hstore_plpython before hstore, but I could live
withthat.
 

Observe that this allows you to write a isbn_plpython module that would expose parsers for ISBN for python (or
json_plpython),as well as hstore_perl, isbn_tcl and so on. It piggybacks on the rendezvous variables mechanism, and
maybein the future you could get some kind of official support in the backend for this kind of things (ie. a hash table
inTopLevelContext keyed on the OIDs of the type and the language).
 

So I'm going to try this approach now.

Cheers,
Jan


pgsql-hackers by date:

Previous
From: Peter Geoghegan
Date:
Subject: Re: Segfault related to pg_authid when running initdb from git master
Next
From: Magnus Hagander
Date:
Subject: Default mode for shutdown