From b04bf41f997f83c5834079e3cbf1702d73708780 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Fri, 7 May 2010 17:17:28 +0100 Subject: [PATCH] Fixed decimal to float recipe to avoid using FLOAT. FLOAT seems not working with NULLs. --- doc/src/faq.rst | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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