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: (view raw, whole thread or download thread mbox)
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

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.


-- 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-2017 The PostgreSQL Global Development Group