Skip site navigation (1) Skip section navigation (2)

Re: JSON type caster

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Tobias Oberstein <tobias(dot)oberstein(at)gmail(dot)com>
Cc: psycopg(at)postgresql(dot)org
Subject: Re: JSON type caster
Date: 2012-09-18 20:24:44
Message-ID: CA+mi_8bT4CgQPgXg+6=1Q=65-gMAWZWHZ4Jy+uLCwfb6y2LrBA@mail.gmail.com (view raw or flat)
Thread:
Lists: psycopg
On Tue, Sep 18, 2012 at 9:12 PM, Tobias Oberstein
<tobias(dot)oberstein(at)gmail(dot)com> wrote:

> If there is no other "default mapping" of Python dicts to any other
> PG type, that would make a nice fallback that probably allows to handle
> a lot of situations automatically - such as stored procs that expect
> their JSON args to be dicts anyway.

I think it can be easily done: currently there's no default adaptation
for dicts: there is the hstore adapter but it must be registered
manually.

If we have the Json wrapper, I suspect adapting dicts would be just a matter of:

    register_adapter(dict, Json)

it would work with lists and other objects as well, but overriding the
default adapter (e.g. lists to arrays etc.). Because adapters are
currently global this may result in unwanted side effects.

It is definitely an use case to be mentioned in the docs.

Cheers,

-- Daniele


In response to

psycopg by date

Next:From: Daniele VarrazzoDate: 2012-09-19 03:35:45
Subject: Re: JSON type caster
Previous:From: Tobias ObersteinDate: 2012-09-18 20:16:49
Subject: Re: JSON type caster

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group