summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-05-07 17:17:28 +0100
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>2010-05-15 14:27:24 +0100
commitb04bf41f997f83c5834079e3cbf1702d73708780 (patch)
tree1672dd8178c8d21abe3852f51c84646b56329560
parent5e3f240ac96ddb27dee4cb03f1c857be1ced8ff9 (diff)
downloadpsycopg2-b04bf41f997f83c5834079e3cbf1702d73708780.tar.gz
Fixed decimal to float recipe to avoid using FLOAT.
FLOAT seems not working with NULLs.
-rw-r--r--doc/src/faq.rst5
1 files changed, 2 insertions, 3 deletions
diff --git a/doc/src/faq.rst b/doc/src/faq.rst
index 4fae77a..e754a42 100644
--- a/doc/src/faq.rst
+++ b/doc/src/faq.rst
@@ -80,13 +80,12 @@ My database is Unicode, but I receive all the strings as UTF-8 `str`. Can I rece
See :ref:`unicode-handling` for the gory details.
Psycopg converts :sql:`decimal`\/\ :sql:`numeric` database types into Python `!Decimal` objects. Can I have `!float` instead?
- You can register the `~psycopg2.extensions.FLOAT` typecaster to be used in
- place of `~psycopg2.extensions.DECIMAL`::
+ You can register a customized adapter for PostgreSQL decimal type::
DEC2FLOAT = psycopg2.extensions.new_type(
psycopg2.extensions.DECIMAL.values,
'DEC2FLOAT',
- psycopg2.extensions.FLOAT)
+ lambda value, curs: float(value) if value is not None else None)
psycopg2.extensions.register_type(DEC2FLOAT)
See :ref:`type-casting-from-sql-to-python` to read the relevant