Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc411f2

Browse files
committed
Table function support for PL/Python
This allows functions with multiple OUT parameters returning both oneor multiple records (RECORD or SETOF RECORD).Jan Urbański, reviewed by Hitoshi Harada
1 parent772dcfe commitbc411f2

File tree

9 files changed

+748
-51
lines changed

9 files changed

+748
-51
lines changed

‎doc/src/sgml/plpython.sgml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -390,18 +390,6 @@ $$ LANGUAGE plpythonu;
390390
return type and the Python data type of the actual return object
391391
are not flagged; the value will be converted in any case.
392392
</para>
393-
394-
<tip>
395-
<para>
396-
<application>PL/Python</application> functions cannot return
397-
either type <type>RECORD</type> or <type>SETOF RECORD</type>. A
398-
workaround is to write a <application>PL/pgSQL</application>
399-
function that creates a temporary table, have it call the
400-
<application>PL/Python</application> function to fill the table,
401-
and then have the <application>PL/pgSQL</application> function
402-
return the generic <type>RECORD</type> from the temporary table.
403-
</para>
404-
</tip>
405393
</sect2>
406394

407395
<sect2>
@@ -593,6 +581,17 @@ $$ LANGUAGE plpythonu;
593581
</varlistentry>
594582
</variablelist>
595583
</para>
584+
585+
<para>
586+
Functions with <literal>OUT</literal> parameters are also supported. For example:
587+
<programlisting>
588+
CREATE FUNCTION multiout_simple(OUT i integer, OUT j integer) AS $$
589+
return (1, 2)
590+
$$ LANGUAGE plpythonu;
591+
592+
SELECT * FROM multiout_simple();
593+
</programlisting>
594+
</para>
596595
</sect2>
597596

598597
<sect2>
@@ -692,6 +691,19 @@ $$ LANGUAGE plpythonu;
692691
</varlistentry>
693692
</variablelist>
694693
</para>
694+
695+
<para>
696+
Set-returning functions with <literal>OUT</literal> parameters
697+
(using <literal>RETURNS SETOF record</literal>) are also
698+
supported. For example:
699+
<programlisting>
700+
CREATE FUNCTION multiout_simple_setof(n integer, OUT integer, OUT integer) RETURNS SETOF record AS $$
701+
return [(1, 2)] * n
702+
$$ LANGUAGE plpythonu;
703+
704+
SELECT * FROM multiout_simple_setof(3);
705+
</programlisting>
706+
</para>
695707
</sect2>
696708
</sect1>
697709

‎src/pl/plpython/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ REGRESS = \
8080
plpython_error\
8181
plpython_unicode\
8282
plpython_quote\
83+
plpython_composite\
8384
plpython_drop
8485
# where to find psql for running the tests
8586
PSQLDIR =$(bindir)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp