Skip to content

Commit a6fa7a3

Browse files
committed
Document that decoding real may result in a different representation
Inexact `real` values change their decimal representation when decoded into a double-precision Python float. See issue #306.
1 parent 1154729 commit a6fa7a3

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

docs/usage.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ The table below shows the correspondence between PostgreSQL and Python types.
126126
| ``interval`` | :class:`datetime.timedelta \ |
127127
| | <python:datetime.timedelta>` |
128128
+----------------------+-----------------------------------------------------+
129-
| ``float``, | :class:`float <python:float>` |
129+
| ``float``, | :class:`float <python:float>` [#f1]_ |
130130
| ``double precision`` | |
131131
+----------------------+-----------------------------------------------------+
132132
| ``smallint``, | :class:`int <python:int>` |
@@ -157,6 +157,11 @@ The table below shows the correspondence between PostgreSQL and Python types.
157157

158158
All other types are encoded and decoded as text by default.
159159

160+
.. [#f1] Inexact single-precision ``float`` values may have a different
161+
representation when decoded into a Python float. This is inherent
162+
to the implementation of limited-precision floating point types.
163+
If you need the decimal representation to match, cast the expression
164+
to ``double`` or ``numeric`` in your query.
160165
161166
.. _asyncpg-custom-codecs:
162167

0 commit comments

Comments
 (0)