Re: jsonb and nested hstore

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: Andres Freund <andres(at)2ndquadrant(dot)com>
Cc: Teodor Sigaev <teodor(at)sigaev(dot)ru>, PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: jsonb and nested hstore
Date: 2014-02-10 12:27:59
Message-ID: 52F8C5CF.4060605@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


On 02/10/2014 05:05 AM, Andres Freund wrote:
> Hi,
>
> On 2014-02-06 18:47:31 -0500, Andrew Dunstan wrote:
>> * switching to using text representation in jsonb send/recv
>> +/*
>> + * jsonb type recv function
>> + *
>> + * the type is sent as text in binary mode, so this is almost the same
>> + * as the input function.
>> + */
>> +Datum
>> +jsonb_recv(PG_FUNCTION_ARGS)
>> +{
>> + StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
>> + text *result = cstring_to_text_with_len(buf->data, buf->len);
>> +
>> + return deserialize_json_text(result);
>> +}
>> +/*
>> + * jsonb type send function
>> + *
>> + * Just send jsonb as a string of text
>> + */
>> +Datum
>> +jsonb_send(PG_FUNCTION_ARGS)
>> +{
>> + Jsonb *jb = PG_GETARG_JSONB(0);
>> + StringInfoData buf;
>> + char *out;
>> +
>> + out = JsonbToCString(NULL, (JB_ISEMPTY(jb)) ? NULL : VARDATA(jb), VARSIZE(jb));
>> +
>> + pq_begintypsend(&buf);
>> + pq_sendtext(&buf, out, strlen(out));
>> + PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
>> +}
> I'd suggest making the format discernible from possible different future
> formats, to allow introducing a proper binary at some later time. Maybe
> just send a int8 first, containing the format.
>

Teodor privately suggested something similar. I was thinking of just
sending a version byte, which for now would be '\x01'. An int8 seems
like more future-proofing provision than we really need.

cheers

andrew

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-02-10 12:39:04 Re: jsonb and nested hstore
Previous Message Etsuro Fujita 2014-02-10 12:00:47 Re: inherit support for foreign tables