| From: | Hannu Krosing <hannu(at)2ndQuadrant(dot)com> | 
|---|---|
| To: | Andres Freund <andres(at)2ndquadrant(dot)com>, 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:10:59 | 
| Message-ID: | 52F8A5B3.5080809@2ndQuadrant.com | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
On 02/10/2014 11: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.
+10
Especially as this is one type where we may want add type-specific
compression options at some point
Cheers
-- 
Hannu Krosing
PostgreSQL Consultant
Performance, Scalability and High Availability
2ndQuadrant Nordic OÜ
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Marti Raudsepp | 2014-02-10 10:33:27 | Re: PoC: Partial sort | 
| Previous Message | Andres Freund | 2014-02-10 10:05:22 | Re: jsonb and nested hstore |