|
1 |
| -<!-- $PostgreSQL: pgsql/doc/src/sgml/plpython.sgml,v 1.47 2010/03/21 02:24:29 momjian Exp $ --> |
| 1 | +<!-- $PostgreSQL: pgsql/doc/src/sgml/plpython.sgml,v 1.48 2010/03/29 21:20:58 petere Exp $ --> |
2 | 2 |
|
3 | 3 | <chapter id="plpython">
|
4 | 4 | <title>PL/Python - Python Procedural Language</title>
|
@@ -243,7 +243,7 @@ $$ LANGUAGE plpythonu;
|
243 | 243 | </para>
|
244 | 244 | </sect1>
|
245 | 245 |
|
246 |
| - <sect1> |
| 246 | + <sect1 id="plpython-data"> |
247 | 247 | <title>Data Values</title>
|
248 | 248 | <para>
|
249 | 249 | Generally speaking, the aim of PL/Python is to provide
|
@@ -364,6 +364,18 @@ $$ LANGUAGE plpythonu;
|
364 | 364 | return type and the Python data type of the actual return object
|
365 | 365 | are not flagged; the value will be converted in any case.
|
366 | 366 | </para>
|
| 367 | + |
| 368 | + <tip> |
| 369 | + <para> |
| 370 | + <application>PL/Python</application> functions cannot return |
| 371 | + either type <type>RECORD</type> or <type>SETOF RECORD</type>. A |
| 372 | + workaround is to write a <application>PL/pgSQL</application> |
| 373 | + function that creates a temporary table, have it call the |
| 374 | + <application>PL/Python</application> function to fill the table, |
| 375 | + and then have the <application>PL/pgSQL</application> function |
| 376 | + return the generic <type>RECORD</type> from the temporary table. |
| 377 | + </para> |
| 378 | + </tip> |
367 | 379 | </sect2>
|
368 | 380 |
|
369 | 381 | <sect2>
|
@@ -866,6 +878,20 @@ rv = plpy.execute(plan, [ "name" ], 5)
|
866 | 878 | The third argument is the limit and is optional.
|
867 | 879 | </para>
|
868 | 880 |
|
| 881 | + <para> |
| 882 | + Query parameters and result row fields are converted between |
| 883 | + PostgreSQL and Python data types as described |
| 884 | + in <xref linkend="plpython-data">. The exception is that composite |
| 885 | + types are currently not supported: They will be rejected as query |
| 886 | + parameters and are converted to strings when appearing in a query |
| 887 | + result. As a workaround for the latter problem, the query can |
| 888 | + sometimes be rewritten so that the composite type result appears as |
| 889 | + a result row rather than as a field of the result row. |
| 890 | + Alternatively, the resulting string could be parsed apart by hand, |
| 891 | + but this approach is not recommended because it is not |
| 892 | + future-proof. |
| 893 | + </para> |
| 894 | + |
869 | 895 | <para>
|
870 | 896 | When you prepare a plan using the PL/Python module it is
|
871 | 897 | automatically saved. Read the SPI documentation (<xref
|
|
0 commit comments