mirror of
https://github.com/postgres/postgres.git
synced 2025-06-25 01:02:05 +03:00
PL/Python: Convert numeric to Decimal
The old implementation converted PostgreSQL numeric to Python float, which was always considered a shortcoming. Now numeric is converted to the Python Decimal object. Either the external cdecimal module or the standard library decimal module are supported. From: Szymon Guz <mabewlun@gmail.com> From: Ronan Dunklau <rdunklau@gmail.com> Reviewed-by: Steve Singer <steve@ssinger.info>
This commit is contained in:
@ -310,12 +310,23 @@ $$ LANGUAGE plpythonu;
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
PostgreSQL <type>real</type>, <type>double</type>,
|
||||
and <type>numeric</type> are converted to
|
||||
Python <type>float</type>. Note that for
|
||||
the <type>numeric</type> this loses information and can lead to
|
||||
incorrect results. This might be fixed in a future
|
||||
release.
|
||||
PostgreSQL <type>real</type> and <type>double</type> are converted to
|
||||
Python <type>float</type>.
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
<listitem>
|
||||
<para>
|
||||
PostgreSQL <type>numeric</type> is converted to
|
||||
Python <type>Decimal</type>. This type is imported from
|
||||
the <literal>cdecimal</literal> package if that is available.
|
||||
Otherwise,
|
||||
<literal>decimal.Decimal</literal> from the standard library will be
|
||||
used. <literal>cdecimal</literal> is significantly faster
|
||||
than <literal>decimal</literal>. In Python 3.3,
|
||||
however, <literal>cdecimal</literal> has been integrated into the
|
||||
standard library under the name <literal>decimal</literal>, so there is
|
||||
no longer any difference.
|
||||
</para>
|
||||
</listitem>
|
||||
|
||||
|
Reference in New Issue
Block a user