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

From: Craig Ringer <craig(at)2ndQuadrant(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Using hstore, json, lo, etc from C extensions?
Date: 2012-11-09 06:05:54
Message-ID: 509C9D42.8090003@2ndQuadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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
<http://www.postgresql.org/docs/9.2/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
<http://www.postgresql.org/docs/9.2/static/extend-extensions.html>

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2012-11-09 06:10:29 Re: Running out of memory while making a join
Previous Message Bruce Momjian 2012-11-09 03:02:35 Re: Does PostgreSQL have complete functional test cases?