diff --git a/doc/src/faq.rst b/doc/src/faq.rst index 4fae77af..e754a427 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