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

Commit8258289

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 parent900a8d5 commit8258289

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
@@ -398,17 +398,25 @@ use strict;
398398
<variablelist>
399399
<varlistentry>
400400
<term>
401-
<literal><function>spi_exec_query</function>(<replaceable>query</replaceable> [, <replaceable>max-rows</replaceable>])</literal>
401+
<literal><function>spi_exec_query</function>(<replaceable>query</replaceable> [, <replaceable>limit</replaceable>])</literal>
402402
<indexterm>
403403
<primary>spi_exec_query</primary>
404404
<secondary>in PL/Perl</secondary>
405405
</indexterm>
406406
</term>
407407
<listitem>
408408
<para>
409-
<literal>spi_exec_query</literal> executes an SQL command and
410-
returns the entire row set as a reference to an array of hash
411-
references. <emphasis>You should only use this command when you know
409+
<function>spi_exec_query</function> executes an SQL command and
410+
returns the entire row set as a reference to an array of hash references.
411+
If <replaceable>limit</replaceable> is specified and is greater than zero,
412+
then <function>spi_exec_query</function> retrieves at
413+
most <replaceable>limit</replaceable> rows, much as if the query included
414+
a <literal>LIMIT</literal> clause. Omitting <replaceable>limit</replaceable>
415+
or specifying it as zero results in no row limit.
416+
</para>
417+
418+
<para>
419+
<emphasis>You should only use this command when you know
412420
that the result set will be relatively small.</emphasis> Here is an
413421
example of a query (<command>SELECT</command> command) with the
414422
optional maximum number of rows:
@@ -600,7 +608,10 @@ $plan = spi_prepare('SELECT * FROM test WHERE id &gt; $1 AND name = $2',
600608
by <literal>spi_exec_query</literal>, or in <literal>spi_query_prepared</literal> which returns a cursor
601609
exactly as <literal>spi_query</literal> does, which can be later passed to <literal>spi_fetchrow</literal>.
602610
The optional second parameter to <literal>spi_exec_prepared</literal> is a hash reference of attributes;
603-
the only attribute currently supported is <literal>limit</literal>, which sets the maximum number of rows returned by a query.
611+
the only attribute currently supported is <literal>limit</literal>, which
612+
sets the maximum number of rows returned from the query.
613+
Omitting <literal>limit</literal> or specifying it as zero results in no
614+
row limit.
604615
</para>
605616

606617
<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