Re: Change in datetime type casting

Поиск
Список
Период
Сортировка
От Karsten Hilbert
Тема Re: Change in datetime type casting
Дата
Msg-id 20120629145916.GC7188@hermes.hilbert.loc
обсуждение исходный текст
Ответ на Re: Change in datetime type casting  (Adrian Klaver <adrian.klaver@gmail.com>)
Ответы Re: Change in datetime type casting
Список psycopg
On Fri, Jun 29, 2012 at 07:51:44AM -0700, Adrian Klaver wrote:

> >>Which begs the question why does the adapter not do str(value) when creating
> >>the ARRAY?
> >
> >Because it would give a false promise of working. If I put a date in
> >my db, I'm expecting a date to come out: any other result is an error.
> >The hstore adapter is documented to take strings mapping: results with
> >any other mapping is undefined. A better behaviour could be to
> >explicitly raise an explicit exception, but it would be less efficient
> >than trusting the user he is using the adapter as documented (see
> >HstoreAdapter._getquoted_9(): we adapt the dict.values() list, not
> >iterate on each values).
> >
> >If writing a date in and reading a string out is enough for your
> >application, you can easily write your own specialized hstore adapter
> >based on the code in extras.py.
>
> The following change in extras.py solves the problem for dates and
> other non string types.:
>
> class HstoreAdapter(object):
>     """Adapt a Python dict to the hstore syntax."""
>     def __init__(self, wrapped):
>         self.wrapped = wrapped
>         for k in self.wrapped:                     <--
>             self.wrapped[k] = str(self.wrapped[k]) <--
>
> Is there a possibility it could find its way into psycopg2 proper?

It would not solve this concern voiced above:

> >Because it would give a false promise of working.

Karsten
--
GPG key ID E4071346 @ gpg-keyserver.de
E167 67FD A291 2BEA 73BD  4537 78B9 A9F9 E407 1346

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

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Change in datetime type casting
Следующее
От: Federico Di Gregorio
Дата:
Сообщение: Re: Change in datetime type casting