Commit 075ab425 authored by Tom Lane's avatar Tom Lane

Document that PL/Python now returns floats using repr() not str().

Commit 1ce7a57c neglected to update the user-facing documentation,
which described the old behavior precisely.
parent adb49504
...@@ -288,8 +288,9 @@ $$ LANGUAGE plpythonu; ...@@ -288,8 +288,9 @@ $$ LANGUAGE plpythonu;
<sect2> <sect2>
<title>Data Type Mapping</title> <title>Data Type Mapping</title>
<para> <para>
Function arguments are converted from their PostgreSQL type to a When a PL/Python function is called, its arguments are converted from
corresponding Python type: their PostgreSQL data type to a corresponding Python type:
<itemizedlist> <itemizedlist>
<listitem> <listitem>
<para> <para>
...@@ -322,7 +323,7 @@ $$ LANGUAGE plpythonu; ...@@ -322,7 +323,7 @@ $$ LANGUAGE plpythonu;
Otherwise, Otherwise,
<literal>decimal.Decimal</literal> from the standard library will be <literal>decimal.Decimal</literal> from the standard library will be
used. <literal>cdecimal</literal> is significantly faster used. <literal>cdecimal</literal> is significantly faster
than <literal>decimal</literal>. In Python 3.3, than <literal>decimal</literal>. In Python 3.3 and up,
however, <literal>cdecimal</literal> has been integrated into the however, <literal>cdecimal</literal> has been integrated into the
standard library under the name <literal>decimal</literal>, so there is standard library under the name <literal>decimal</literal>, so there is
no longer any difference. no longer any difference.
...@@ -356,8 +357,9 @@ $$ LANGUAGE plpythonu; ...@@ -356,8 +357,9 @@ $$ LANGUAGE plpythonu;
</para> </para>
<para> <para>
Function return values are converted to the declared PostgreSQL When a PL/Python function returns, its return value is converted to the
return data type as follows: function's declared PostgreSQL return data type as follows:
<itemizedlist> <itemizedlist>
<listitem> <listitem>
<para> <para>
...@@ -373,16 +375,18 @@ $$ LANGUAGE plpythonu; ...@@ -373,16 +375,18 @@ $$ LANGUAGE plpythonu;
When the PostgreSQL return type is <type>bytea</type>, the When the PostgreSQL return type is <type>bytea</type>, the
return value will be converted to a string (Python 2) or bytes return value will be converted to a string (Python 2) or bytes
(Python 3) using the respective Python built-ins, with the (Python 3) using the respective Python built-ins, with the
result being converted <type>bytea</type>. result being converted to <type>bytea</type>.
</para> </para>
</listitem> </listitem>
<listitem> <listitem>
<para> <para>
For all other PostgreSQL return types, the returned Python For all other PostgreSQL return types, the return value is converted
value is converted to a string using the Python to a string using the Python built-in <literal>str</literal>, and the
built-in <literal>str</literal>, and the result is passed to the result is passed to the input function of the PostgreSQL data type.
input function of the PostgreSQL data type. (If the Python value is a <type>float</>, it is converted using
the <literal>repr</> built-in instead of <literal>str</literal>, to
avoid loss of precision.)
</para> </para>
<para> <para>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment