mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-01-31 17:34:08 +03:00
Fixed decimal to float recipe to avoid using FLOAT.
FLOAT seems not working with NULLs.
This commit is contained in:
parent
5e3f240ac9
commit
b04bf41f99
|
@ -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.
|
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?
|
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
|
You can register a customized adapter for PostgreSQL decimal type::
|
||||||
place of `~psycopg2.extensions.DECIMAL`::
|
|
||||||
|
|
||||||
DEC2FLOAT = psycopg2.extensions.new_type(
|
DEC2FLOAT = psycopg2.extensions.new_type(
|
||||||
psycopg2.extensions.DECIMAL.values,
|
psycopg2.extensions.DECIMAL.values,
|
||||||
'DEC2FLOAT',
|
'DEC2FLOAT',
|
||||||
psycopg2.extensions.FLOAT)
|
lambda value, curs: float(value) if value is not None else None)
|
||||||
psycopg2.extensions.register_type(DEC2FLOAT)
|
psycopg2.extensions.register_type(DEC2FLOAT)
|
||||||
|
|
||||||
See :ref:`type-casting-from-sql-to-python` to read the relevant
|
See :ref:`type-casting-from-sql-to-python` to read the relevant
|
||||||
|
|
Loading…
Reference in New Issue
Block a user