Re: JSONB marshalling - Mailing list psycopg

From Daniele Varrazzo
Subject Re: JSONB marshalling
Date
Msg-id CA+mi_8bd_g-MDPMwa88w0HXfjysaLFcrCza90+KL9zpRGbxKWg@mail.gmail.com
Whole thread Raw
In response to JSONB marshalling  (Damian Dimmich <damian@tauri-tec.com>)
Responses Re: JSONB marshalling  (Guido Notari <gnotari@linkgroup.it>)
List psycopg
On 7/22/14, Damian Dimmich <damian@tauri-tec.com> wrote:
> Hello,
>
> I'm testing out the jsonb functionality on postgres 9.4 and up.  I added
> an extension to sqlalchemy which enables nicer jsonb access through the
> orm and extends support for all the query types:
>
> http://docs.sqlalchemy.org/en/rel_0_9/dialects/postgresql.html?highlight=json#sqlalchemy.dialects.postgresql.JSON
>
> The psycopg2 driver doesn't recognise jsonb yet however and results
> don't get run through json.reads.
>
> According to http://schinckel.net/2014/05/24/python,-postgres-and-jsonb/
> the oid and typarray are 3802 and 3807 respectively.
>
> Are there any plans to add jsonb support to psycopg2, and/or is someone
> working on this already?

Hello Damian,

for what I understand the jsonb type has exactly the same textual
representation of the regular json, so it should be enough to call

    psycopg2.extras.register_json(oid=3802, array_oid=3807, globally=True)

to get jsonb support for the entire process.

Of course this should be handled by psycopg by default: somebody has
found default automatic json unmarshalling questionable for the json
type, but now it's in, and I'd find an asymmetric support for jsonb
surprising. So yes, I'd add a register_default_jsonb() function (which
just calls register_json() with the known oids) and I'd call it
initially with the default unmarshall function.

When would this happen? I don't think we can say it's a bugfix and
it's a change in the adapter behaviour so I think it should be
released in a future 2.6, which is still unplanned and I don't see
many new features to release. OTOH PG 9.4 has not been released yet
and the jsonb oids have never been used in the wild (user-defined
types get bigger oids, right?) so if there was interest in it we could
consider its release in 2.5.4, which would be released in a much
shorter time.

Does any opinionated person have an opinion?

Thank you

-- Daniele


psycopg by date:

Previous
From: Damian Dimmich
Date:
Subject: JSONB marshalling
Next
From: Guido Notari
Date:
Subject: Re: JSONB marshalling