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

Commit88969ea

Browse files
committed
Fix incorrect documentation of plperl's method for accessing the number
of rows processed by a SPI query (David Fetter); also some other minoreditorial cleanup (Tom Lane).
1 parent8e57975 commit88969ea

File tree

1 file changed

+37
-37
lines changed

1 file changed

+37
-37
lines changed

‎doc/src/sgml/plperl.sgml

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.30 2004/11/06 14:32:10 petere Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/plperl.sgml,v 2.31 2004/11/19 23:22:54 tgl Exp $
33
-->
44

55
<chapter id="plperl">
@@ -66,7 +66,7 @@ $$ LANGUAGE plperl;
6666

6767
<para>
6868
Arguments and results are handled as in any other Perl subroutine:
69-
Arguments are passed in <varname>@_</varname>, and a result value
69+
arguments are passed in <varname>@_</varname>, and a result value
7070
is returned with <literal>return</> or as the last expression
7171
evaluated in the function.
7272
</para>
@@ -77,7 +77,7 @@ $$ LANGUAGE plperl;
7777

7878
<programlisting>
7979
CREATE FUNCTION perl_max (integer, integer) RETURNS integer AS $$
80-
if ($_[0]> $_[1]) { return $_[0]; }
80+
if ($_[0]&gt; $_[1]) { return $_[0]; }
8181
return $_[1];
8282
$$ LANGUAGE plperl;
8383
</programlisting>
@@ -106,7 +106,7 @@ CREATE FUNCTION perl_max (integer, integer) RETURNS integer AS $$
106106
return $b;
107107
}
108108
if (! defined $b) { return $a; }
109-
if ($a> $b) { return $a; }
109+
if ($a&gt; $b) { return $a; }
110110
return $b;
111111
$$ LANGUAGE plperl;
112112
</programlisting>
@@ -129,7 +129,7 @@ CREATE TABLE employee (
129129

130130
CREATE FUNCTION empcomp(employee) RETURNS integer AS $$
131131
my ($emp) = @_;
132-
return $emp->{basesalary} + $emp->{bonus};
132+
return $emp-&gt;{basesalary} + $emp-&gt;{bonus};
133133
$$ LANGUAGE plperl;
134134

135135
SELECT name, empcomp(employee) FROM employee;
@@ -174,16 +174,17 @@ SELECT name, empcomp(employee) FROM employee;
174174
<programlisting>
175175
$rv = spi_exec_query('SELECT * FROM my_table', 5);
176176
</programlisting>
177-
This returns up to 5 rows from the table
178-
<literal>my_table</literal>. If <literal>my_table</literal>
179-
has a column <literal>my_column</literal>,it could be accessed
180-
like this:
177+
This returns up to 5 rows from the table
178+
<literal>my_table</literal>. If <literal>my_table</literal>
179+
has a column <literal>my_column</literal>,you can get that
180+
value from row <literal>$i</literal> of the resultlike this:
181181
<programlisting>
182-
$foo = $rv->{rows}[$i]->{my_column};
182+
$foo = $rv-&gt;{rows}[$i]-&gt;{my_column};
183183
</programlisting>
184-
The total number of rows returned can be accessed like this:
184+
The total number of rows returned from a <command>SELECT</command>
185+
query can be accessed like this:
185186
<programlisting>
186-
$nrows =@{$rv->{rows}};
187+
$nrows = $rv-&gt;{processed}
187188
</programlisting>
188189
</para>
189190

@@ -196,11 +197,11 @@ $rv = spi_exec_query($query);
196197
You can then access the command status (e.g.,
197198
<literal>SPI_OK_INSERT</literal>) like this:
198199
<programlisting>
199-
$res = $rv->{status};
200+
$res = $rv-&gt;{status};
200201
</programlisting>
201202
To get the number of rows affected, do:
202203
<programlisting>
203-
$nrows = $rv->{rows};
204+
$nrows = $rv-&gt;{processed};
204205
</programlisting>
205206
</para>
206207
</listitem>
@@ -260,13 +261,12 @@ INSERT INTO test (i, v) VALUES (4, 'immortal');
260261
CREATE FUNCTION test_munge() RETURNS SETOF test AS $$
261262
my $res = [];
262263
my $rv = spi_exec_query('select i, v from test;');
263-
my $status = $rv->{status};
264-
my $rows = @{$rv->{rows}};
265-
my $processed = $rv->{processed};
266-
foreach my $rn (0 .. $rows - 1) {
267-
my $row = $rv->{rows}[$rn];
268-
$row->{i} += 200 if defined($row->{i});
269-
$row->{v} =~ tr/A-Za-z/a-zA-Z/ if (defined($row->{v}));
264+
my $status = $rv-&gt;{status};
265+
my $nrows = $rv-&gt;{processed};
266+
foreach my $rn (0 .. $nrows - 1) {
267+
my $row = $rv-&gt;{rows}[$rn];
268+
$row-&gt;{i} += 200 if defined($row-&gt;{i});
269+
$row-&gt;{v} =~ tr/A-Za-z/a-zA-Z/ if (defined($row-&gt;{v}));
270270
push @$res, $row;
271271
}
272272
return $res;
@@ -283,7 +283,7 @@ SELECT * FROM test_munge();
283283
CREATE TYPE testrowperl AS (f1 integer, f2 text, f3 text);
284284

285285
CREATE OR REPLACE FUNCTION perl_row() RETURNS testrowperl AS $$
286-
return {f2 => 'hello', f1 => 1, f3 => 'world'};
286+
return {f2 =&gt; 'hello', f1 =&gt; 1, f3 =&gt; 'world'};
287287
$$ LANGUAGE plperl;
288288
</programlisting>
289289
</para>
@@ -298,12 +298,12 @@ CREATE TYPE testsetperl AS (f1 integer, f2 text, f3 text);
298298

299299
CREATE OR REPLACE FUNCTION perl_set() RETURNS SETOF testsetperl AS $$
300300
return [
301-
{ f1 => 1, f2 => 'Hello', f3 => 'World' },
302-
{ f1 => 2, f2 => 'Hello', f3 => 'PostgreSQL' },
303-
{ f1 => 3, f2 => 'Hello', f3 => 'PL/Perl' }
301+
{ f1 =&gt; 1, f2 =&gt; 'Hello', f3 =&gt; 'World' },
302+
{ f1 =&gt; 2, f2 =&gt; 'Hello', f3 =&gt; 'PostgreSQL' },
303+
{ f1 =&gt; 3, f2 =&gt; 'Hello', f3 =&gt; 'PL/Perl' }
304304
];
305305
$$ LANGUAGE plperl;
306-
</programlisting>
306+
</programlisting>
307307
</para>
308308
</sect1>
309309

@@ -359,7 +359,7 @@ SELECT get_var('sample');
359359
system operations are not allowed for security reasons:
360360
<programlisting>
361361
CREATE FUNCTION badfunc() RETURNS integer AS $$
362-
open(TEMP, ">/tmp/badfile");
362+
open(TEMP, "&gt;/tmp/badfile");
363363
print TEMP "Gotcha!\n";
364364
return 1;
365365
$$ LANGUAGE plperl;
@@ -397,14 +397,14 @@ $$ LANGUAGE plperl;
397397
<title>PL/Perl Triggers</title>
398398

399399
<para>
400-
PL/Perl can be used to write trigger functions.The global hash
401-
reference <varname>$_TD</varname> contains information about the
402-
current trigger event. Theparts of <varname>$_TD</varname> hash
400+
PL/Perl can be used to write trigger functions.In a trigger function,
401+
the hashreference <varname>$_TD</varname> contains information about the
402+
current trigger event. Thefields of the <varname>$_TD</varname> hash
403403
reference are:
404404

405405
<variablelist>
406406
<varlistentry>
407-
<term><literal>$_TD->{new}{foo}</literal></term>
407+
<term><literal>$_TD-&gt;{new}{foo}</literal></term>
408408
<listitem>
409409
<para>
410410
<literal>NEW</literal> value of column <literal>foo</literal>
@@ -413,7 +413,7 @@ $$ LANGUAGE plperl;
413413
</varlistentry>
414414

415415
<varlistentry>
416-
<term><literal>$_TD->{old}{foo}</literal></term>
416+
<term><literal>$_TD-&gt;{old}{foo}</literal></term>
417417
<listitem>
418418
<para>
419419
<literal>OLD</literal> value of column <literal>foo</literal>
@@ -488,7 +488,7 @@ $$ LANGUAGE plperl;
488488
<term><literal>$_TD{argc}</literal></term>
489489
<listitem>
490490
<para>
491-
Number of arguments of the triggerfunctions
491+
Number of arguments of the triggerfunction
492492
</para>
493493
</listitem>
494494
</varlistentry>
@@ -521,7 +521,7 @@ $$ LANGUAGE plperl;
521521
<term><literal>"MODIFY"</literal></term>
522522
<listitem>
523523
<para>
524-
Indicates that the <literal>NEW</literal>rows was modified by
524+
Indicates that the <literal>NEW</literal>row was modified by
525525
the trigger function
526526
</para>
527527
</listitem>
@@ -539,10 +539,10 @@ CREATE TABLE test (
539539
);
540540

541541
CREATE OR REPLACE FUNCTION valid_id() RETURNS trigger AS $$
542-
if (($_TD->{new}{i} &gt;= 100) || ($_TD->{new}{i} &lt;= 0)) {
542+
if (($_TD-&gt;{new}{i} &gt;= 100) || ($_TD-&gt;{new}{i} &lt;= 0)) {
543543
return "SKIP"; # skip INSERT/UPDATE command
544-
} elsif ($_TD->{new}{v} ne "immortal") {
545-
$_TD->{new}{v} .= "(modified by trigger)";
544+
} elsif ($_TD-&gt;{new}{v} ne "immortal") {
545+
$_TD-&gt;{new}{v} .= "(modified by trigger)";
546546
return "MODIFY"; # modify row and execute INSERT/UPDATE command
547547
} else {
548548
return; # execute INSERT/UPDATE command

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp