pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Kevin Wooten <kdubb@me.com>
Cc: Dave Cramer <davecramer@gmail.com>
Cc: List <pgsql-jdbc@postgresql.org>
Subject: Re: PostgreSQL gaps wrt to java, and jdbc
Date: Tue, 07 Jul 2015 23:30:26 +0300
Message-ID: <559C36E2.10202@iki.fi> (raw)
In-Reply-To: <5973AC3D-69C0-4CE8-A5FD-D3F045480543@me.com>
References: <CADK3HHLfJEx5i0CgvP=dGBXHUiHAcvTu0QeDoQTkyne42xn3fA@mail.gmail.com>
	<80FEC5E5-DD36-46F4-A510-31E08415FBB1@me.com>
	<559C2CA8.6000200@iki.fi>
	<CADK3HH+pVqc+8iMEx-QRNUVPa1D5ZVtS+0ynYpO6B=bfBYpK7w@mail.gmail.com>
	<559C3053.2060106@iki.fi>
	<5973AC3D-69C0-4CE8-A5FD-D3F045480543@me.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-jdbc>

On 07/07/2015 11:08 PM, Kevin Wooten wrote:
>
>> On Jul 7, 2015, at 1:02 PM, Heikki Linnakangas <hlinnaka@iki.fi> wrote:
>>
>> On 07/07/2015 10:51 PM, Dave Cramer wrote:
>>> Is there a way to get json and or xml out as binary ?
>>
>> Well, as far as the protocol is considered, yes. However, the
>> "binary representation" of json and xml datatypes is not too
>> exciting; here's the binary send function for json for example:
>>
>> /*
>> * Binary send.
>> */
>> Datum
>> json_send(PG_FUNCTION_ARGS)
>> {
>>         text       *t = PG_GETARG_TEXT_PP(0);
>>         StringInfoData buf;
>>
>>         pq_begintypsend(&buf);
>>         pq_sendtext(&buf, VARDATA_ANY(t), VARSIZE_ANY_EXHDR(t));
>>         PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
>> }
>>
>> I.e. it just sends the string with a bytea header. There is no
>> benefit to using that instead of the regular text representation.
>> That dummy representation is used just so that e.g. binary-format
>> pg_dump works.
>
> This confused me when we went to implement this as a binary type.
> Isn’t it stored in a binary format? Or is that just an intermediate
> format that’s cached around inside the server?

Json is stored as text. It's really nothing more than a text field with 
a validation step in the input function to check that it's valid json. 
It preserves formatting and all.

Jsonb is stored in a binary format, but funnily enough its "binary 
representation" in the protocol is mostly text:

> /*
>  * jsonb type send function
>  *
>  * Just send jsonb as a version number, then a string of text
>  */
> Datum
> jsonb_send(PG_FUNCTION_ARGS)
> {
> 	Jsonb	   *jb = PG_GETARG_JSONB(0);
> 	StringInfoData buf;
> 	StringInfo	jtext = makeStringInfo();
> 	int			version = 1;
>
> 	(void) JsonbToCString(jtext, &jb->root, VARSIZE(jb));
>
> 	pq_begintypsend(&buf);
> 	pq_sendint(&buf, version, 1);
> 	pq_sendtext(&buf, jtext->data, jtext->len);
> 	pfree(jtext->data);
> 	pfree(jtext);
>
> 	PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
> }

There's a version number there, so perhaps we'll replace that with 
something more binary in the future ;-)

- Heikki



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



view thread (21+ messages)  latest in thread

Message-ID: <559C36E2.10202@iki.fi>
Permalink:  ../559C36E2.10202@iki.fi/
Also on:    postgresql.org/message-id/559C36E2.10202@iki.fi

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-jdbc@postgresql.org
  Cc: hlinnaka@iki.fi, kdubb@me.com, davecramer@gmail.com
  Subject: Re: PostgreSQL gaps wrt to java, and jdbc
  In-Reply-To: <559C36E2.10202@iki.fi>
  References: <CADK3HHLfJEx5i0CgvP=dGBXHUiHAcvTu0QeDoQTkyne42xn3fA@mail.gmail.com> <80FEC5E5-DD36-46F4-A510-31E08415FBB1@me.com> <559C2CA8.6000200@iki.fi> <CADK3HH+pVqc+8iMEx-QRNUVPa1D5ZVtS+0ynYpO6B=bfBYpK7w@mail.gmail.com> <559C3053.2060106@iki.fi> <5973AC3D-69C0-4CE8-A5FD-D3F045480543@me.com> <559C36E2.10202@iki.fi>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox