diff options
author | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-04-14 01:05:36 +0100 |
---|---|---|
committer | Daniele Varrazzo <daniele.varrazzo@gmail.com> | 2010-04-14 01:05:36 +0100 |
commit | 431920b3676ffecc80fd7f0bc25d774d6e5a2aa1 (patch) | |
tree | a43c9515e1abd120bdd9d491f2f79ba497eb2316 | |
parent | 0ac4c8ac1724d7f849e8b8ac63ab49d16251dabe (diff) | |
download | psycopg2-431920b3676ffecc80fd7f0bc25d774d6e5a2aa1.tar.gz |
Added recipe to get Python floats from Postgres decimals in the FAQ.
-rw-r--r-- | doc/src/faq.rst | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/doc/src/faq.rst b/doc/src/faq.rst index b45d103..8015864 100644 --- a/doc/src/faq.rst +++ b/doc/src/faq.rst @@ -70,6 +70,20 @@ 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`:: + + DEC2FLOAT = psycopg2.extensions.new_type( + psycopg2.extensions.DECIMAL.values, + 'DEC2FLOAT', + psycopg2.extensions.FLOAT) + psycopg2.extensions.register_type(DEC2FLOAT) + + See :ref:`type-casting-from-sql-to-python` to read the relevant + documentation. If you find `!psycopg2.extensions.DECIMAL` not avalable, use + `!psycopg2._psycopg.DECIMAL` instead. + I can't compile `!psycopg2`: the compiler says *error: Python.h: No such file or directory*. What am I missing? You need to install a Python development package: it is usually called ``python-dev``. |