Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZCZWO-00063E-7j for pgsql-jdbc@arkaria.postgresql.org; Tue, 07 Jul 2015 20:31:16 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZCZWN-000327-LI for pgsql-jdbc@arkaria.postgresql.org; Tue, 07 Jul 2015 20:31:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZCZVh-0002OT-Ob for pgsql-jdbc@postgresql.org; Tue, 07 Jul 2015 20:30:33 +0000 Received: from mail-wi0-x236.google.com ([2a00:1450:400c:c05::236]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZCZVd-0002RU-PI for pgsql-jdbc@postgresql.org; Tue, 07 Jul 2015 20:30:32 +0000 Received: by wibdq8 with SMTP id dq8so194095583wib.1 for ; Tue, 07 Jul 2015 13:30:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:reply-to:user-agent:mime-version:to:cc :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=FB+EqarMJmXWIpiBHa3PYM2tfWhJ+R7mlyLDjEP52OA=; b=gV5eU/0Wj2BxZqrD1h2N7BvDTTSS9UVJFIjhvwb/VODadYmk89kNJ93CYbdPjgzL2W +LKOGUKuoddnHuNB+MQRl4ep+wlUP6UfNaEWFxm7zDILFzGk9drgKToPSCXiV+hCOpKw TU11UenfmYlmBmN8kiS5+Gz0v3bg6OWJRwXyd89cmIuQF5qcn8RYn4sTJcSIZdcecL5J XiVKD7SilkwVW8GirQ6ExaWy5JQ58+28a/aHg993ipwBC8PsBcuOjBfOOD8R3kxGFYbR tcMTnkg6F+ZwYwWor1BzjYgI3A1eMa9PI6cm/u9xtqg6Vo6uDWULSLIIb9LWiHdV+DI2 V5Xw== X-Received: by 10.194.2.228 with SMTP id 4mr11311140wjx.146.1436301028829; Tue, 07 Jul 2015 13:30:28 -0700 (PDT) Received: from [192.168.1.110] (dsl-hkibrasgw1-58c38f-82.dhcp.inet.fi. [88.195.143.82]) by mx.google.com with ESMTPSA id wx9sm35123787wjb.6.2015.07.07.13.30.27 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Jul 2015 13:30:28 -0700 (PDT) Message-ID: <559C36E2.10202@iki.fi> Date: Tue, 07 Jul 2015 23:30:26 +0300 From: Heikki Linnakangas Reply-To: hlinnaka@iki.fi User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.7.0 MIME-Version: 1.0 To: Kevin Wooten CC: Dave Cramer , List Subject: Re: PostgreSQL gaps wrt to java, and jdbc References: <80FEC5E5-DD36-46F4-A510-31E08415FBB1@me.com> <559C2CA8.6000200@iki.fi> <559C3053.2060106@iki.fi> <5973AC3D-69C0-4CE8-A5FD-D3F045480543@me.com> In-Reply-To: <5973AC3D-69C0-4CE8-A5FD-D3F045480543@me.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -2.4 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org On 07/07/2015 11:08 PM, Kevin Wooten wrote: > >> On Jul 7, 2015, at 1:02 PM, Heikki Linnakangas 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