Re: JSON type caster

Поиск
Список
Период
Сортировка
От Daniele Varrazzo
Тема Re: JSON type caster
Дата
Msg-id CA+mi_8bRAZP107BF5hrTMy4VaK3BGsApcU=r-T2ksrQvc0KpCg@mail.gmail.com
обсуждение исходный текст
Ответ на Re: JSON type caster  (Tobias Oberstein <tobias.oberstein@gmail.com>)
Ответы Re: JSON type caster  (Tobias Oberstein <tobias.oberstein@gmail.com>)
Re: JSON type caster  (Daniele Varrazzo <daniele.varrazzo@gmail.com>)
Список psycopg
On Tue, Sep 18, 2012 at 4:57 PM, Tobias Oberstein
<tobias.oberstein@gmail.com> wrote:

> Personally, I am mainly calling stored procedures, i.e.
>
> select proname, prorettype, proargtypes from pg_proc where proname =
> 'create_employee';
>
> create_employee,114,114
>
> => a SP which takes 1 JSON arg, and has return type JSON.
>
> The return type casting is taken care of by the (new) SQL=>Py JSON caster.
>
> The argument type isn't handled automatically.
>
> Given the stuff above (Json() thin wrapper), I still need to determine
> the input arg type from pg_proc ... there isn't any "magic" I can turn
> on with Psycopg, right?

Right, this would be the shortcoming. Unfortunately there is no Python
class representing a json, and the mapping object -> adapter is by
python class only. I assume your create_employee function cannot take
*any* json: it may be expecting e.g. a dict and not a list, and maybe
some specific attributes while ignoring others. For this case it's
probably easy to create a Python object that knows how to adapt to
json syntax. But in the generic case a Json can be a python string, or
a list, or a dict, or None, each of which have a more reasonable
Postgres representation.

If anybody comes with a better solution than the Json wrapper I'd be
happy to know.

BTW, because of the zope problem discussed today, I'd be happy to have
a release soon, so if nobody steps ahead in the next few hours, I'll
try and implement the json support tonight and have it for psycopg
2.4.6.

-- Daniele


В списке psycopg по дате отправления:

Предыдущее
От: Tobias Oberstein
Дата:
Сообщение: Re: JSON type caster
Следующее
От: "Jonathan S. Katz"
Дата:
Сообщение: Range Type Support