Fixed decimal to float recipe to avoid using FLOAT.

FLOAT seems not working with NULLs.
This commit is contained in:
Daniele Varrazzo 2010-05-07 17:17:28 +01:00
parent 5e3f240ac9
commit b04bf41f99

View File

@ -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