summaryrefslogtreecommitdiff
path: root/doc/src
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-02-15 17:30:43 +0000
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2011-02-15 17:30:43 +0000
commit3ae2f221b38719ccd9c91321b0031c0b1d68a9d6 (patch)
treec58ea79305266e67ead44d978cdadaf75d619742 /doc/src
parentc96ba553dadd921b9e1e0b3d66092a4182036a55 (diff)
downloadpsycopg2-3ae2f221b38719ccd9c91321b0031c0b1d68a9d6.tar.gz
Adapt bytearray and memoryview to bytes if available
Diffstat (limited to 'doc/src')
-rw-r--r--doc/src/usage.rst23
1 files changed, 19 insertions, 4 deletions
diff --git a/doc/src/usage.rst b/doc/src/usage.rst
index 60a2428..2f16a98 100644
--- a/doc/src/usage.rst
+++ b/doc/src/usage.rst
@@ -244,12 +244,27 @@ the SQL string that would be sent to the database.
.. index::
single: Buffer; Adaptation
single: bytea; Adaptation
+ single: bytes; Adaptation
+ single: bytearray; Adaptation
+ single: memoryview; Adaptation
single: Binary string
-- Binary types: Python types such as `!bytes`, `!bytearray`, `!buffer`,
- `!memoryview` are converted in PostgreSQL binary string syntax, suitable for
- :sql:`bytea` fields. Received data is returned as `!buffer` (in Python 2) or
- `!memoryview` (in Python 3).
+- Binary types: Python types representing binary objects are converted in
+ PostgreSQL binary string syntax, suitable for :sql:`bytea` fields. Such
+ types are `!buffer` (only available in Python 2), `!memoryview` (available
+ from Python 2.7), `!bytearray` (available from Python 2.6) and `!bytes`
+ (only form Python 3: the name is available from Python 2.6 but it's only an
+ alias for the type `!str`). Received data is returned as `!buffer` (in
+ Python 2) or `!memoryview` (in Python 3).
+
+ .. note::
+
+ In Python 2, if you have binary data in a `!str` object, you can pass them
+ to a :sql:`bytea` field using the `psycopg2.Binary` wrapper::
+
+ mypic = open('picture.png', 'rb').read()
+ curs.execute("insert into blobs (file) values (%s)",
+ (psycopg2.Binary(mypic),))
.. warning::