From: | Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com> |
---|---|
To: | Federico Di Gregorio <fog(at)dndg(dot)it> |
Cc: | psycopg(at)postgresql(dot)org |
Subject: | Re: Change in datetime type casting |
Date: | 2012-07-03 01:25:49 |
Message-ID: | CA+mi_8ZJ9o+tp03sbxw1+nayE+FVfv+a3cU8L78mz7fN3dXXzA@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | psycopg |
On Mon, Jul 2, 2012 at 9:24 AM, Federico Di Gregorio <fog(at)dndg(dot)it> wrote:
> 2) Throw an exception if keys/values aren't strings and force the user
> to convert the data before trying to send it to the hstore.
We can definitely add a check to verify every key is a basestring and
every value is a basestring or null (this is exactly the hstore
domain). It is an extra iteration to be performed on the entire
content of the dict though.
Something on a slightly different note we could do: adapt takes a
protocol as input (undocumented I believe, defaulting to ISQLQuote,
currently the only protocol used): if we added a parameter to the
protocol, defaulting to the current extensions.adapters we could have:
- adaptation of hstore keys is performed on a limited set of
datatypes: only str and unicode. Trying to pass another type in a dict
would raise an adaptation error;
- adaptation of hstore values is performed on the same types plus None;
- if s.b. wanted to map other types into an hstore they can add other
adapters just on the HstoreAdapter object (the object returned by
register_adapter)
- we can have adapters map per connection/cursor, other argument
touched in this thread.
So we stay strict in the default you have independently verified are
the only sane default choice, allow for extension by users who know
what they want to do and get a nice symmetry between adaptation and
type casting.
As an interface, register_adapter() could take an extra context as
register_type() does: it could be a connection, a cursor or an
HstoreAdapter (e.g. it could be whatever object exporting a method
add_adapter() or something along this line).
This is an idea of 3am after the PyBirra: if nothing makes sense here,
please ignore.
-- Daniele
From | Date | Subject | |
---|---|---|---|
Next Message | Matthieu Rigal | 2012-07-03 09:59:02 | insert into with a dictionary, or generally with a variable number of columns |
Previous Message | Federico Di Gregorio | 2012-07-02 08:24:44 | Re: Change in datetime type casting |