summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/src/extras.rst24
-rw-r--r--doc/src/usage.rst10
-rw-r--r--lib/extras.py12
3 files changed, 40 insertions, 6 deletions
diff --git a/doc/src/extras.rst b/doc/src/extras.rst
index 19f055b..b2f4ea3 100644
--- a/doc/src/extras.rst
+++ b/doc/src/extras.rst
@@ -87,6 +87,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::
pair: UUID; Data types
UUID data type
diff --git a/doc/src/usage.rst b/doc/src/usage.rst
index d398515..bea38ac 100644
--- a/doc/src/usage.rst
+++ b/doc/src/usage.rst
@@ -186,6 +186,7 @@ argument of the `~cursor.execute()` method::
.. index::
+ single: Adaptation
pair: Objects; 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
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::
single: Unicode
diff --git a/lib/extras.py b/lib/extras.py
index e81aedb..dc98fdb 100644
--- a/lib/extras.py
+++ b/lib/extras.py
@@ -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
is different in every database. The typecaster will be registered only on
the connection or cursor passed as argument. If your application uses a
- single database you can pass *globally*=True to have hstore registered on
- all the connections.
-
- Raise `~psycopg2.ProgrammingError` if hstore is not installed in the
- target database.
+ single database you can pass *globally*\=True to have hstore registered
+ on all the connections.
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)
if oids is None: