diff options
| author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-11-19 13:13:14 +0000 |
|---|---|---|
| committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-11-19 13:13:14 +0000 |
| commit | f2c5d04f39cd9b7c4415316d92538daa2f39aab9 (patch) | |
| tree | d6dc12f53ceb654234aefdc61ba745fe3756341f /doc/src/faq.rst | |
| parent | 21dfc2c5924dcce2912152b908e5b6c80d7b473e (diff) | |
| download | psycopg2-f2c5d04f39cd9b7c4415316d92538daa2f39aab9.tar.gz | |
Fixed docs: the execute argument must be a sequence, not a tuple.
Diffstat (limited to 'doc/src/faq.rst')
| -rw-r--r-- | doc/src/faq.rst | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/doc/src/faq.rst b/doc/src/faq.rst index 4cc2ee6..c271b62 100644 --- a/doc/src/faq.rst +++ b/doc/src/faq.rst @@ -63,7 +63,7 @@ I can't pass an integer or a float parameter to my query: it says *a number is r >>> cur.execute("INSERT INTO numbers VALUES (%s)", (42,)) # correct I try to execute a query but it fails with the error *not all arguments converted during string formatting* (or *object does not support indexing*). Why? - Psycopg always require positional arguments to be passed as a tuple, even + Psycopg always require positional arguments to be passed as a sequence, even when the query takes a single parameter. And remember that to make a single item tuple in Python you need a comma! See :ref:`query-parameters`. :: @@ -71,6 +71,7 @@ I try to execute a query but it fails with the error *not all arguments converte >>> cur.execute("INSERT INTO foo VALUES (%s)", "bar") # WRONG >>> cur.execute("INSERT INTO foo VALUES (%s)", ("bar")) # WRONG >>> cur.execute("INSERT INTO foo VALUES (%s)", ("bar",)) # correct + >>> cur.execute("INSERT INTO foo VALUES (%s)", ["bar"]) # correct My database is Unicode, but I receive all the strings as UTF-8 `str`. Can I receive `unicode` objects instead? The following magic formula will do the trick:: |
