Re: JSONB marshalling

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Damian Dimmich <damian(at)tauri-tec(dot)com>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: JSONB marshalling
Date: 2014-07-24 21:05:34
Message-ID: CA+mi_8bd_g-MDPMwa88w0HXfjysaLFcrCza90+KL9zpRGbxKWg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On 7/22/14, Damian Dimmich <damian(at)tauri-tec(dot)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

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Guido Notari 2014-07-25 16:01:15 Re: JSONB marshalling
Previous Message Damian Dimmich 2014-07-22 10:03:47 JSONB marshalling