Access to receive/output functions from libpq client - Mailing list pgsql-interfaces

From Martin Kleppmann
Subject Access to receive/output functions from libpq client
Date
Msg-id D7E62929-32EC-4664-BBB2-7EE3595379A1@kleppmann.com
Whole thread Raw
List pgsql-interfaces
Hi,

I'm trying to export the contents of a PG database to an external format, using 9.4's exciting new logical decoding
facility.I am currently writing an output plugin for logical replication (using PGXS). To capture a snapshot of the
databefore the replication slot was created, I am using libpq to set up a transaction with the replication slot's
exportedsnapshot, and doing a "select * from table". 

In this context, my question is about decoding datatypes. An output plugin sees the changed tuples in binary format, it
canfind the the OID of a datum, and use PG's functions to decode the datum -- for example, it can use DatumGetNumeric()
toget a Numeric struct, and it can use OidOutputFunctionCall() to get the text representation of a datum. That's very
nice.

In the external client, when doing PQsendQueryParams() I can choose between binary and text result format. I'd like to
beable to request the binary format and use the same conversion functions as in the output plugin. This would allow the
datato be exported in a structured representation, and only falling back to using a datatype's output function to get a
stringrepresentation if we don't know what to do with a particular OID. 

My problem is that the libpq client doesn't have access to the same library functions as the output plugin. The linker
complainsabout undefined symbols _OidOutputFunctionCall, _getTypeOutputInfo and _pg_detoast_datum, for example. 

Is there a library that I could link into the libpq client to provide the functions for decoding binary datatypes? Or
isthere some other recommended way of decoding binary datums in a client? 

Thanks,
Martin




pgsql-interfaces by date:

Previous
From: Michael Wallner
Date:
Subject: New PHP binding: pecl/pq
Next
From: Bill Clay
Date:
Subject: libpq connect keepalive* parms: no effect!?