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

Commit6b97e43

Browse files
committed
Add warning about plperl nested named subroutines
Andrew Dunstan
1 parent0a28eb4 commit6b97e43

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

‎doc/src/sgml/plperl.sgml

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.45 2005/08/24 19:16:49 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.46 2005/10/12 14:28:33 momjian Exp $
33
-->
44

55
<chapter id="plperl">
@@ -53,22 +53,34 @@ CREATE FUNCTION <replaceable>funcname</replaceable> (<replaceable>argument-types
5353
# PL/Perl function body
5454
$$ LANGUAGE plperl;
5555
</programlisting>
56-
The body of the function is ordinary Perl code. A PL/Perl function must
56+
The body of the function is ordinary Perl code. In fact, the PL/Perl
57+
glue code wraps it inside a Perl subroutine. A PL/Perl function must
5758
always return a scalar value. You can return more complex structures
5859
(arrays, records, and sets) by returning a reference, as discussed below.
5960
Never return a list.
6061
</para>
6162

63+
<note>
6264
<para>
63-
The syntax of the <command>CREATE FUNCTION</command> command requires
64-
the function body to be written as a string constant. It is usually
65-
most convenient to use dollar quoting (see <xref
66-
linkend="sql-syntax-dollar-quoting">) for the string constant.
67-
If you choose to use regular single-quoted string constant syntax,
68-
you must escape single quote marks (<literal>'</>) and backslashes
69-
(<literal>\</>) used in the body of the function, typically by
70-
doubling them (see <xref linkend="sql-syntax-strings">).
65+
The use of named nested subroutines is dangerous in Perl, especially if
66+
they refer to lexical variables in the enclosing scope. Because a PL/Perl
67+
function is wrapped in a subroutine, any named subroutine you create will
68+
be nested. In general, it is far safer to create anonymous subroutines
69+
which you call via a coderef. See the <literal>perldiag</literal>
70+
man page for more details.
7171
</para>
72+
</note>
73+
74+
<para>
75+
The syntax of the <command>CREATE FUNCTION</command> command requires
76+
the function body to be written as a string constant. It is usually
77+
most convenient to use dollar quoting (see <xref
78+
linkend="sql-syntax-dollar-quoting">) for the string constant.
79+
If you choose to use regular single-quoted string constant syntax,
80+
you must escape single quote marks (<literal>'</>) and backslashes
81+
(<literal>\</>) used in the body of the function, typically by
82+
doubling them (see <xref linkend="sql-syntax-strings">).
83+
</para>
7284

7385
<para>
7486
Arguments and results are handled as in any other Perl subroutine:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp