Re: jsonb and nested hstore

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
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 10:05:22
Message-ID: 20140210100522.GE26601@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Hannu Krosing 2014-02-10 10:10:59 Re: jsonb and nested hstore
Previous Message Hannu Krosing 2014-02-10 09:41:47 Re: jsonb and nested hstore