Thread: Using hstore, json, lo, etc from C extensions?

Using hstore, json, lo, etc from C extensions?

From
Craig Ringer
Date:
Hi all

With the growing number of extensions that expose useful and increasingly widely used custom data types, I'm wondering: is there any way to use them from a C extension without going through the SPI?

A look at the sources for hstore and json shows that they mostly define static functions and don't present much of an external C API. But say they did; if I or someone else wrote a proper C level API for use of hstore from other C extensions. Is there any way to actually link to it and use it from another C extension?

It looks like extensions can use `requires` to express dependencies on each other ( http://www.postgresql.org/docs/current/static/extend-extensions.html) ... but is there any way to express a *linkage* dependency for C-level use, to actually link to hstore and use its non-static functions?

As far as I can tell the only way to do it at the moment would be to extract most of the guts from the `hstore` extension into a `libhstore` that both the hstore extension and other extensions could link to. There doesn't seem to be provision for doing that in the extension building infrastructure, so it seems it'd be a manual hackjob.

I realise you can still use other extensions via the SPI, I'm just wondering about direct C level usage for performance critical or specialized tasks. With the growing popularity of hstore, the interest in json, etc, this is likely to start coming up more.

Question originally prompted by this SO post: http://stackoverflow.com/questions/13302682/postgresql-udf-in-c-using-hstore

--
Craig Ringer

Re: Using hstore, json, lo, etc from C extensions?

From
Tom Lane
Date:
Craig Ringer <craig@2ndQuadrant.com> writes:
> With the growing number of extensions that expose useful and
> increasingly widely used custom data types, I'm wondering: is there any
> way to use them from a C extension without going through the SPI?

Invoke the extension's exposed SQL functions at fmgr level?

            regards, tom lane


Re: Using hstore, json, lo, etc from C extensions?

From
Craig Ringer
Date:
On 11/09/2012 02:12 PM, Tom Lane wrote:
> Craig Ringer <craig@2ndQuadrant.com> writes:
>> With the growing number of extensions that expose useful and
>> increasingly widely used custom data types, I'm wondering: is there any
>> way to use them from a C extension without going through the SPI?
> Invoke the extension's exposed SQL functions at fmgr level?
That's certainly a lot better than using the SPI. Probably good enough
for most uses, really. Good point, and thanks.

--
Craig Ringer