pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Daniel Gustafsson <daniel@yesql.se>
Cc: Kieran McCusker <kieran.mccusker@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: plpython does not honour max-rows
Date: Tue, 02 May 2023 16:35:45 -0400
Message-ID: <2829787.1683059745@sss.pgh.pa.us> (raw)
In-Reply-To: <2678018.1683036150@sss.pgh.pa.us>
References: <CAGgUQ6H6qYScctOhktQ9HLFDDoafBKHyUgJbZ6q_dOApnzNTXg@mail.gmail.com>
	<711512C7-2BC2-4901-A368-6A5A23023F72@yesql.se>
	<CAGgUQ6GBpw-vkzxuuTk3au8Hq+YezG5sv3yR=YjE3CbOqp-a3Q@mail.gmail.com>
	<D2132F23-B3AF-4D98-9859-BC2B64A599EC@yesql.se>
	<CAGgUQ6FMfBrCTeu7DLUmmsSVn0zu02mx7xZ39etb26pAqTrM+w@mail.gmail.com>
	<2678018.1683036150@sss.pgh.pa.us>

I wrote:
> Since that's stood for a few decades now, changing it seems impossible
> from the backwards-compatibility standpoint.  However, it does seem
> appropriate to repeat that material in the wrapper's documentation.
> I wonder whether the similar plperl and pltcl wrappers are also
> documentation-shy here.

Indeed so.  The underlying SPI documentation is solid enough on this
point, but the PLs are all misleading, in that they suggest the limit
arguments work like "LIMIT n" or "FETCH n", which isn't quite so.
I suggest the attached docs patch.

			regards, tom lane

Attachments:

fix-PL-limit-documentation.patch (text/x-diff, 5.2K) download diff --git a/doc/src/sgml/plperl.sgml b/doc/src/sgml/plperl.sgml index 6c81ee8fbe..8ab9602249 100644 --- a/doc/src/sgml/plperl.sgml +++ b/doc/src/sgml/plperl.sgml @@ -441,7 +441,7 @@ use strict; <variablelist> <varlistentry> <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> <primary>spi_exec_query</primary> <secondary>in PL/Perl</secondary> @@ -449,9 +449,14 @@ use strict; </term> <listitem> <para> - <literal>spi_exec_query</literal> executes an SQL command and -returns the entire row set as a reference to an array of hash -references. <emphasis>You should only use this command when you know + <function>spi_exec_query</function> executes an SQL command and +returns the entire row set as a reference to an array of hash references. +If <replaceable>limit</replaceable> is specified, +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 <literal>limit</literal> or +specifying it as zero results in no row limit. +<emphasis>You should only use this command when you know that the result set will be relatively small.</emphasis> Here is an example of a query (<command>SELECT</command> command) with the optional maximum number of rows: @@ -643,7 +648,10 @@ $plan = spi_prepare('SELECT * FROM test WHERE id &gt; $1 AND name = $2', 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>. 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> diff --git a/doc/src/sgml/plpython.sgml b/doc/src/sgml/plpython.sgml index e190c90f45..2dd6ea6b32 100644 --- a/doc/src/sgml/plpython.sgml +++ b/doc/src/sgml/plpython.sgml @@ -789,7 +789,7 @@ $$ LANGUAGE plpython3u; <variablelist> <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> <para> Calling <function>plpy.execute</function> with a query string and an @@ -797,6 +797,15 @@ $$ LANGUAGE plpython3u; be returned in a result object. </para> + <para> + If <replaceable>limit</replaceable> is specified, + then <function>plpy.execute</function> retrieves at + most <replaceable>limit</replaceable> rows, much as if the query + included a <literal>LIMIT</literal> + clause. Omitting <literal>limit</literal> or specifying it as zero + results in no row limit. + </para> + <para> The result object emulates a list or dictionary object. The result object can be accessed by row number and column name. For example: @@ -887,7 +896,7 @@ foo = rv[i]["my_column"] <varlistentry> <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> <para> <indexterm><primary>preparing a query</primary><secondary>in PL/Python</secondary></indexterm> diff --git a/doc/src/sgml/pltcl.sgml b/doc/src/sgml/pltcl.sgml index bf56ba6b1c..b31f2c1330 100644 --- a/doc/src/sgml/pltcl.sgml +++ b/doc/src/sgml/pltcl.sgml @@ -341,9 +341,11 @@ $$ LANGUAGE pltcl; </para> <para> The optional <literal>-count</literal> value tells - <function>spi_exec</function> the maximum number of rows - to process in the command. The effect of this is comparable to - setting up a query as a cursor and then saying <literal>FETCH <replaceable>n</replaceable></literal>. + <function>spi_exec</function> to stop + once <replaceable>n</replaceable> rows have been retrieved, + 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> If the command is a <command>SELECT</command> statement, the values of the

view thread (12+ messages)  latest in thread

Message-ID: <2829787.1683059745@sss.pgh.pa.us>
Permalink:  ../2829787.1683059745@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2829787.1683059745@sss.pgh.pa.us

 ·  · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, daniel@yesql.se, kieran.mccusker@gmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: plpython does not honour max-rows
  In-Reply-To: <2829787.1683059745@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox