Added some documentation for the hstore adaptation.

This commit is contained in:
Daniele Varrazzo 2010-09-27 02:25:09 +01:00
parent d5bf400cb4
commit 4b98e8941f
3 changed files with 40 additions and 6 deletions

View File

@ -86,6 +86,30 @@ Logging cursor
.. index::
pair: hstore; Data types
pair: dict; Adaptation
Hstore data type
----------------
Python `dict` objects can be converted into the PostgreSQL |hstore|_ data
type. Only dictionaries with string/unicode keys and values are supported.
None are also allowed as values.
The |hstore| type has received a lot of improvements in the PostgreSQL 9.0
release and the Psycopg adapter uses a more efficient representation if the
new release is detected.
.. |hstore| replace:: :sql:`hstore`
.. _hstore: http://www.postgresql.org/docs/9.0/static/hstore.html
.. autofunction:: register_hstore
.. index:: .. index::
pair: UUID; Data types pair: UUID; Data types

View File

@ -186,6 +186,7 @@ argument of the `~cursor.execute()` method::
.. index:: .. index::
single: Adaptation
pair: Objects; Adaptation pair: Objects; Adaptation
single: Data types; Adaptation single: Data types; Adaptation
@ -294,6 +295,15 @@ the SQL string that would be sent to the database.
was necessary to import the `~psycopg2.extensions` module to have it was necessary to import the `~psycopg2.extensions` module to have it
registered. registered.
- Python dictionaries are converted into the |hstore|_ data type. See
`~psycopg2.extras.register_hstore()` for further details.
.. |hstore| replace:: :sql:`hstore`
.. _hstore: http://www.postgresql.org/docs/9.0/static/hstore.html
.. versionadded:: 2.2.3
the :sql:`hstore` adaptation.
.. index:: .. index::
single: Unicode single: Unicode

View File

@ -620,14 +620,14 @@ def register_hstore(conn_or_curs, globally=False, unicode=False):
The function must receive a connection or cursor as the :sql:`hstore` oid The function must receive a connection or cursor as the :sql:`hstore` oid
is different in every database. The typecaster will be registered only on is different in every database. The typecaster will be registered only on
the connection or cursor passed as argument. If your application uses a the connection or cursor passed as argument. If your application uses a
single database you can pass *globally*=True to have hstore registered on single database you can pass *globally*\=True to have hstore registered
all the connections. on all the connections.
Raise `~psycopg2.ProgrammingError` if hstore is not installed in the
target database.
By default the returned dicts have string keys and values: use By default the returned dicts have string keys and values: use
*unicode*=True to return `unicode` objects instead. *unicode*\=True to return `unicode` objects instead.
Raise `~psycopg2.ProgrammingError` if the :sql:`hstore` type is not
installed in the target database.
""" """
oids = HstoreAdapter.get_oids(conn_or_curs) oids = HstoreAdapter.get_oids(conn_or_curs)
if oids is None: if oids is None: