Re: Bug in documentation: https://www.postgresql.org/docs/current/spi-examples.html

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Curt Kolovson <ckolovson(at)gmail(dot)com>
Cc: pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: Bug in documentation: https://www.postgresql.org/docs/current/spi-examples.html
Date: 2023-07-18 00:26:26
Message-ID: CAKFQuwbN7gzyEh-LBkXh+68xH8NS3QumYG8Tj6XVzG6zDvSuWg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs

On Mon, Jul 17, 2023 at 4:53 PM Curt Kolovson <ckolovson(at)gmail(dot)com> wrote:

> The actual results (shown below) are different than shown on this doc
> page. The reason is because the second parameter to the UDF that is
> passed to SPI_exec is the maximum number of rows to return, or 0 for
> no limit. It is not the maximum number of rows to process. In the case
> of "SELECT execq('INSERT INTO a SELECT x + 2 FROM a', 1)", it returned
> 0 rows, but it inserted (processed) 2 rows. This example should be
> corrected.
>
>
> db=# SELECT execq('INSERT INTO a SELECT x + 2 FROM a', 1);
> execq
> -------
> 2
> (1 row)
>
>
SPI_exec sees "INSERT 0 2" as the command tag from the SQL command you
passed and so 2 is the output of the execq function call.

No INFO messages appear because you did not include a returning clause.
The 1 you passed to the call is immaterial if the query you supply doesn't
produce a result set.

David J.

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message jian he 2023-07-18 00:34:24 Re: Bug in documentation: https://www.postgresql.org/docs/current/spi-examples.html
Previous Message Curt Kolovson 2023-07-17 23:52:53 Bug in documentation: https://www.postgresql.org/docs/current/spi-examples.html