Accessing structured datatypes using libpq

Started by Raimo Jormakkaalmost 12 years ago5 messagesgeneral
Jump to latest
#1Raimo Jormakka
raimo.jormakka@gmail.com

Hi,

What is the recommended way of accessing structured data-types (especially
JSONB and HSTORE) using libpq? It seems that by default JSONB data for
example is returned as text.

Is it not possible to have binary access to these data-types? If it is
possible, then how do I do it exactly as the only thing I get from libpq is
a void-pointer?

Cheers,
Raimo

#2John R Pierce
pierce@hogranch.com
In reply to: Raimo Jormakka (#1)
Re: Accessing structured datatypes using libpq

On 6/10/2014 11:20 PM, Raimo Jormakka wrote:

What is the recommended way of accessing structured data-types
(especially JSONB and HSTORE) using libpq? It seems that by default
JSONB data for example is returned as text.

Is it not possible to have binary access to these data-types? If it is
possible, then how do I do it exactly as the only thing I get from
libpq is a void-pointer?

those are text data types. there is no binary representations.

--
john r pierce 37N 122W
somewhere on the middle of the left coast

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3Raimo Jormakka
raimo.jormakka@gmail.com
In reply to: John R Pierce (#2)
Re: Accessing structured datatypes using libpq

2014-06-11 9:44 GMT+03:00 John R Pierce <pierce@hogranch.com>:

On 6/10/2014 11:20 PM, Raimo Jormakka wrote:

What is the recommended way of accessing structured data-types
(especially JSONB and HSTORE) using libpq? It seems that by default JSONB
data for example is returned as text.

Is it not possible to have binary access to these data-types? If it is
possible, then how do I do it exactly as the only thing I get from libpq is
a void-pointer?

those are text data types. there is no binary representations.

Can someone elaborate this a bit? Isn't the key distinction between the
JSONB and JSON data-types the fact that the former is a binary format while
the latter one is text-based?

#4Michael Paquier
michael@paquier.xyz
In reply to: Raimo Jormakka (#3)
Re: Accessing structured datatypes using libpq

On Wed, Jun 11, 2014 at 6:59 PM, Raimo Jormakka
<raimo.jormakka@gmail.com> wrote:

2014-06-11 9:44 GMT+03:00 John R Pierce <pierce@hogranch.com>:

On 6/10/2014 11:20 PM, Raimo Jormakka wrote:

What is the recommended way of accessing structured data-types
(especially JSONB and HSTORE) using libpq? It seems that by default JSONB
data for example is returned as text.

Is it not possible to have binary access to these data-types? If it is
possible, then how do I do it exactly as the only thing I get from libpq is
a void-pointer?

those are text data types. there is no binary representations.

Can someone elaborate this a bit? Isn't the key distinction between the
JSONB and JSON data-types the fact that the former is a binary format while
the latter one is text-based?

Internally yes, representation of those data types on disk is
different. However the output result, the one obtained by libpq or any
client is similar in appearance.
--
Michael

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#5Merlin Moncure
mmoncure@gmail.com
In reply to: Raimo Jormakka (#1)
Re: Accessing structured datatypes using libpq

On Wed, Jun 11, 2014 at 1:20 AM, Raimo Jormakka
<raimo.jormakka@gmail.com> wrote:

Hi,

What is the recommended way of accessing structured data-types (especially
JSONB and HSTORE) using libpq? It seems that by default JSONB data for
example is returned as text.

Is it not possible to have binary access to these data-types? If it is
possible, then how do I do it exactly as the only thing I get from libpq is
a void-pointer?

check out libpqtypes: http://libpqtypes.esilo.com/. it gives C client
side representations of most common types including hstore. jsonb is
not supported yet but the library is pluggable to add support for new
types.

merlin

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general