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

Commitb00bae2

Browse files
committed
Doc: clarify behavior of row-limit arguments in the PLs' SPI wrappers.
plperl, plpython, and pltcl all provide query-execution functionsthat are thin wrappers around SPI_execute() or its variants.The SPI functions document their row-count limit arguments clearly,as "maximum number of rows to return, or 0 for no limit". Howeverthe PLs' documentation failed to explain this special behavior ofzero, so that a reader might well assume it means "fetch zerorows". Improve that.Daniel Gustafsson and Tom Lane, per report from Kieran McCuskerDiscussion:https://postgr.es/m/CAGgUQ6H6qYScctOhktQ9HLFDDoafBKHyUgJbZ6q_dOApnzNTXg@mail.gmail.com
1 parentee24b5e commitb00bae2

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

‎doc/src/sgml/plperl.sgml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -441,17 +441,25 @@ use strict;
441441
<variablelist>
442442
<varlistentry>
443443
<term>
444-
<literal><function>spi_exec_query</function>(<replaceable>query</replaceable> [, <replaceable>max-rows</replaceable>])</literal>
444+
<literal><function>spi_exec_query</function>(<replaceable>query</replaceable> [, <replaceable>limit</replaceable>])</literal>
445445
<indexterm>
446446
<primary>spi_exec_query</primary>
447447
<secondary>in PL/Perl</secondary>
448448
</indexterm>
449449
</term>
450450
<listitem>
451451
<para>
452-
<literal>spi_exec_query</literal> executes an SQL command and
453-
returns the entire row set as a reference to an array of hash
454-
references. <emphasis>You should only use this command when you know
452+
<function>spi_exec_query</function> executes an SQL command and
453+
returns the entire row set as a reference to an array of hash references.
454+
If <replaceable>limit</replaceable> is specified and is greater than zero,
455+
then <function>spi_exec_query</function> retrieves at
456+
most <replaceable>limit</replaceable> rows, much as if the query included
457+
a <literal>LIMIT</literal> clause. Omitting <replaceable>limit</replaceable>
458+
or specifying it as zero results in no row limit.
459+
</para>
460+
461+
<para>
462+
<emphasis>You should only use this command when you know
455463
that the result set will be relatively small.</emphasis> Here is an
456464
example of a query (<command>SELECT</command> command) with the
457465
optional maximum number of rows:
@@ -643,7 +651,10 @@ $plan = spi_prepare('SELECT * FROM test WHERE id &gt; $1 AND name = $2',
643651
by <literal>spi_exec_query</literal>, or in <literal>spi_query_prepared</literal> which returns a cursor
644652
exactly as <literal>spi_query</literal> does, which can be later passed to <literal>spi_fetchrow</literal>.
645653
The optional second parameter to <literal>spi_exec_prepared</literal> is a hash reference of attributes;
646-
the only attribute currently supported is <literal>limit</literal>, which sets the maximum number of rows returned by a query.
654+
the only attribute currently supported is <literal>limit</literal>, which
655+
sets the maximum number of rows returned from the query.
656+
Omitting <literal>limit</literal> or specifying it as zero results in no
657+
row limit.
647658
</para>
648659

649660
<para>

‎doc/src/sgml/plpython.sgml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -937,14 +937,23 @@ $$ LANGUAGE plpythonu;
937937

938938
<variablelist>
939939
<varlistentry>
940-
<term><literal>plpy.<function>execute</function>(<replaceable>query</replaceable> [, <replaceable>max-rows</replaceable>])</literal></term>
940+
<term><literal>plpy.<function>execute</function>(<replaceable>query</replaceable> [, <replaceable>limit</replaceable>])</literal></term>
941941
<listitem>
942942
<para>
943943
Calling <function>plpy.execute</function> with a query string and an
944944
optional row limit argument causes that query to be run and the result to
945945
be returned in a result object.
946946
</para>
947947

948+
<para>
949+
If <replaceable>limit</replaceable> is specified and is greater than
950+
zero, then <function>plpy.execute</function> retrieves at
951+
most <replaceable>limit</replaceable> rows, much as if the query
952+
included a <literal>LIMIT</literal>
953+
clause. Omitting <replaceable>limit</replaceable> or specifying it as
954+
zero results in no row limit.
955+
</para>
956+
948957
<para>
949958
The result object emulates a list or dictionary object. The result
950959
object can be accessed by row number and column name. For example:
@@ -1035,7 +1044,7 @@ foo = rv[i]["my_column"]
10351044

10361045
<varlistentry>
10371046
<term><literal>plpy.<function>prepare</function>(<replaceable>query</replaceable> [, <replaceable>argtypes</replaceable>])</literal></term>
1038-
<term><literal>plpy.<function>execute</function>(<replaceable>plan</replaceable> [, <replaceable>arguments</replaceable> [, <replaceable>max-rows</replaceable>]])</literal></term>
1047+
<term><literal>plpy.<function>execute</function>(<replaceable>plan</replaceable> [, <replaceable>arguments</replaceable> [, <replaceable>limit</replaceable>]])</literal></term>
10391048
<listitem>
10401049
<para>
10411050
<indexterm><primary>preparing a query</primary><secondary>in PL/Python</secondary></indexterm>

‎doc/src/sgml/pltcl.sgml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,9 +341,11 @@ $$ LANGUAGE pltcl;
341341
</para>
342342
<para>
343343
The optional <literal>-count</literal> value tells
344-
<function>spi_exec</function> the maximum number of rows
345-
to process in the command. The effect of this is comparable to
346-
setting up a query as a cursor and then saying <literal>FETCH <replaceable>n</replaceable></literal>.
344+
<function>spi_exec</function> to stop
345+
once <replaceable>n</replaceable> rows have been retrieved,
346+
much as if the query included a <literal>LIMIT</literal> clause.
347+
If <replaceable>n</replaceable> is zero, the query is run to
348+
completion, the same as when <literal>-count</literal> is omitted.
347349
</para>
348350
<para>
349351
If the command is a <command>SELECT</command> statement, the values of the

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp