Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6489875

Browse files
committed
Doc: clarify behavior of row-limit arguments in the PLs' SPI wrappers.
plperl, plpython, and pltcl all provide query-execution functions that 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". However the PLs' documentation failed to explain this special behavior of zero, so that a reader might well assume it means "fetch zero rows". Improve that. Daniel Gustafsson and Tom Lane, per report from Kieran McCusker Discussion: https://postgr.es/m/CAGgUQ6H6qYScctOhktQ9HLFDDoafBKHyUgJbZ6q_dOApnzNTXg@mail.gmail.com
1 parent 0823705 commit 6489875

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
@@ -789,14 +789,23 @@ $$ LANGUAGE plpython3u;
789789

790790
<variablelist>
791791
<varlistentry>
792-
<term><literal>plpy.<function>execute</function>(<replaceable>query</replaceable> [, <replaceable>max-rows</replaceable>])</literal></term>
792+
<term><literal>plpy.<function>execute</function>(<replaceable>query</replaceable> [, <replaceable>limit</replaceable>])</literal></term>
793793
<listitem>
794794
<para>
795795
Calling <function>plpy.execute</function> with a query string and an
796796
optional row limit argument causes that query to be run and the result to
797797
be returned in a result object.
798798
</para>
799799

800+
<para>
801+
If <replaceable>limit</replaceable> is specified and is greater than
802+
zero, then <function>plpy.execute</function> retrieves at
803+
most <replaceable>limit</replaceable> rows, much as if the query
804+
included a <literal>LIMIT</literal>
805+
clause. Omitting <replaceable>limit</replaceable> or specifying it as
806+
zero results in no row limit.
807+
</para>
808+
800809
<para>
801810
The result object emulates a list or dictionary object. The result
802811
object can be accessed by row number and column name. For example:
@@ -887,7 +896,7 @@ foo = rv[i]["my_column"]
887896

888897
<varlistentry>
889898
<term><literal>plpy.<function>prepare</function>(<replaceable>query</replaceable> [, <replaceable>argtypes</replaceable>])</literal></term>
890-
<term><literal>plpy.<function>execute</function>(<replaceable>plan</replaceable> [, <replaceable>arguments</replaceable> [, <replaceable>max-rows</replaceable>]])</literal></term>
899+
<term><literal>plpy.<function>execute</function>(<replaceable>plan</replaceable> [, <replaceable>arguments</replaceable> [, <replaceable>limit</replaceable>]])</literal></term>
891900
<listitem>
892901
<para>
893902
<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)