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
This commit is contained in:
parent
77ea05406c
commit
23c7aa865b
@ -441,7 +441,7 @@ use strict;
|
|||||||
<variablelist>
|
<variablelist>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term>
|
<term>
|
||||||
<literal><function>spi_exec_query</function>(<replaceable>query</replaceable> [, <replaceable>max-rows</replaceable>])</literal>
|
<literal><function>spi_exec_query</function>(<replaceable>query</replaceable> [, <replaceable>limit</replaceable>])</literal>
|
||||||
<indexterm>
|
<indexterm>
|
||||||
<primary>spi_exec_query</primary>
|
<primary>spi_exec_query</primary>
|
||||||
<secondary>in PL/Perl</secondary>
|
<secondary>in PL/Perl</secondary>
|
||||||
@ -449,9 +449,17 @@ use strict;
|
|||||||
</term>
|
</term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<literal>spi_exec_query</literal> executes an SQL command and
|
<function>spi_exec_query</function> executes an SQL command and
|
||||||
returns the entire row set as a reference to an array of hash
|
returns the entire row set as a reference to an array of hash references.
|
||||||
references. <emphasis>You should only use this command when you know
|
If <replaceable>limit</replaceable> is specified and is greater than zero,
|
||||||
|
then <function>spi_exec_query</function> retrieves at
|
||||||
|
most <replaceable>limit</replaceable> rows, much as if the query included
|
||||||
|
a <literal>LIMIT</literal> clause. Omitting <replaceable>limit</replaceable>
|
||||||
|
or specifying it as zero results in no row limit.
|
||||||
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
<emphasis>You should only use this command when you know
|
||||||
that the result set will be relatively small.</emphasis> Here is an
|
that the result set will be relatively small.</emphasis> Here is an
|
||||||
example of a query (<command>SELECT</command> command) with the
|
example of a query (<command>SELECT</command> command) with the
|
||||||
optional maximum number of rows:
|
optional maximum number of rows:
|
||||||
@ -643,7 +651,10 @@ $plan = spi_prepare('SELECT * FROM test WHERE id > $1 AND name = $2',
|
|||||||
by <literal>spi_exec_query</literal>, or in <literal>spi_query_prepared</literal> which returns a cursor
|
by <literal>spi_exec_query</literal>, or in <literal>spi_query_prepared</literal> which returns a cursor
|
||||||
exactly as <literal>spi_query</literal> does, which can be later passed to <literal>spi_fetchrow</literal>.
|
exactly as <literal>spi_query</literal> does, which can be later passed to <literal>spi_fetchrow</literal>.
|
||||||
The optional second parameter to <literal>spi_exec_prepared</literal> is a hash reference of attributes;
|
The optional second parameter to <literal>spi_exec_prepared</literal> is a hash reference of attributes;
|
||||||
the only attribute currently supported is <literal>limit</literal>, which sets the maximum number of rows returned by a query.
|
the only attribute currently supported is <literal>limit</literal>, which
|
||||||
|
sets the maximum number of rows returned from the query.
|
||||||
|
Omitting <literal>limit</literal> or specifying it as zero results in no
|
||||||
|
row limit.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
|
@ -789,7 +789,7 @@ $$ LANGUAGE plpython3u;
|
|||||||
|
|
||||||
<variablelist>
|
<variablelist>
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><literal>plpy.<function>execute</function>(<replaceable>query</replaceable> [, <replaceable>max-rows</replaceable>])</literal></term>
|
<term><literal>plpy.<function>execute</function>(<replaceable>query</replaceable> [, <replaceable>limit</replaceable>])</literal></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
Calling <function>plpy.execute</function> with a query string and an
|
Calling <function>plpy.execute</function> with a query string and an
|
||||||
@ -797,6 +797,15 @@ $$ LANGUAGE plpython3u;
|
|||||||
be returned in a result object.
|
be returned in a result object.
|
||||||
</para>
|
</para>
|
||||||
|
|
||||||
|
<para>
|
||||||
|
If <replaceable>limit</replaceable> is specified and is greater than
|
||||||
|
zero, then <function>plpy.execute</function> retrieves at
|
||||||
|
most <replaceable>limit</replaceable> rows, much as if the query
|
||||||
|
included a <literal>LIMIT</literal>
|
||||||
|
clause. Omitting <replaceable>limit</replaceable> or specifying it as
|
||||||
|
zero results in no row limit.
|
||||||
|
</para>
|
||||||
|
|
||||||
<para>
|
<para>
|
||||||
The result object emulates a list or dictionary object. The result
|
The result object emulates a list or dictionary object. The result
|
||||||
object can be accessed by row number and column name. For example:
|
object can be accessed by row number and column name. For example:
|
||||||
@ -887,7 +896,7 @@ foo = rv[i]["my_column"]
|
|||||||
|
|
||||||
<varlistentry>
|
<varlistentry>
|
||||||
<term><literal>plpy.<function>prepare</function>(<replaceable>query</replaceable> [, <replaceable>argtypes</replaceable>])</literal></term>
|
<term><literal>plpy.<function>prepare</function>(<replaceable>query</replaceable> [, <replaceable>argtypes</replaceable>])</literal></term>
|
||||||
<term><literal>plpy.<function>execute</function>(<replaceable>plan</replaceable> [, <replaceable>arguments</replaceable> [, <replaceable>max-rows</replaceable>]])</literal></term>
|
<term><literal>plpy.<function>execute</function>(<replaceable>plan</replaceable> [, <replaceable>arguments</replaceable> [, <replaceable>limit</replaceable>]])</literal></term>
|
||||||
<listitem>
|
<listitem>
|
||||||
<para>
|
<para>
|
||||||
<indexterm><primary>preparing a query</primary><secondary>in PL/Python</secondary></indexterm>
|
<indexterm><primary>preparing a query</primary><secondary>in PL/Python</secondary></indexterm>
|
||||||
|
@ -341,9 +341,11 @@ $$ LANGUAGE pltcl;
|
|||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
The optional <literal>-count</literal> value tells
|
The optional <literal>-count</literal> value tells
|
||||||
<function>spi_exec</function> the maximum number of rows
|
<function>spi_exec</function> to stop
|
||||||
to process in the command. The effect of this is comparable to
|
once <replaceable>n</replaceable> rows have been retrieved,
|
||||||
setting up a query as a cursor and then saying <literal>FETCH <replaceable>n</replaceable></literal>.
|
much as if the query included a <literal>LIMIT</literal> clause.
|
||||||
|
If <replaceable>n</replaceable> is zero, the query is run to
|
||||||
|
completion, the same as when <literal>-count</literal> is omitted.
|
||||||
</para>
|
</para>
|
||||||
<para>
|
<para>
|
||||||
If the command is a <command>SELECT</command> statement, the values of the
|
If the command is a <command>SELECT</command> statement, the values of the
|
||||||
|
Loading…
x
Reference in New Issue
Block a user