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

Commita0558cf

Browse files
committed
Fix checking of query type in plpgsql's RETURN QUERY command.
Prior to v14, we insisted that the query in RETURN QUERY be of a typethat returns tuples. (For instance, INSERT RETURNING was allowed,but not plain INSERT.) That happened indirectly because we opened acursor for the query, so spi.c checked SPI_is_cursor_plan(). As aconsequence, the error message wasn't terribly on-point, but at leastit was there.Commit2f48ede lost this detail. Instead, plain RETURN QUERYinsisted that the query be a SELECT (by checking for SPI_OK_SELECT)while RETURN QUERY EXECUTE failed to check the query type at all.Neither of these changes was intended.The only convenient place to check this in the EXECUTE case is inside_SPI_execute_plan, because we haven't done parse analysis until then.So we need to pass down a flag saying whether to enforce that thequery returns tuples. Fortunately, we can squeeze another booleaninto struct SPIExecuteOptions without an ABI break, since there'spadding space there. (It's unlikely that any extensions wouldalready be using this new struct, but preserving ABI in v14 seemslike a smart idea anyway.)Within spi.c, it seemed like _SPI_execute_plan's parameter listwas already ridiculously long, and I didn't want to make it longer.So I thought of passing SPIExecuteOptions down as-is, allowing thatparameter list to become much shorter. This makes the patch a bitmore invasive than it might otherwise be, but it's all internal tospi.c, so that seems fine.Per report from Marc Bachmann. Back-patch to v14 where thefaulty code came in.Discussion:https://postgr.es/m/1F2F75F0-27DF-406F-848D-8B50C7EEF06A@gmail.com
1 parent2903f14 commita0558cf

File tree

6 files changed

+186
-80
lines changed

6 files changed

+186
-80
lines changed

‎doc/src/sgml/spi.sgml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,17 @@ int SPI_execute_extended(const char *<parameter>command</parameter>,
739739
</listitem>
740740
</varlistentry>
741741

742+
<varlistentry>
743+
<term><literal>bool <parameter>must_return_tuples</parameter></literal></term>
744+
<listitem>
745+
<para>
746+
if <literal>true</literal>, raise error if the query is not of a kind
747+
that returns tuples (this does not forbid the case where it happens to
748+
return zero tuples)
749+
</para>
750+
</listitem>
751+
</varlistentry>
752+
742753
<varlistentry>
743754
<term><literal>uint64 <parameter>tcount</parameter></literal></term>
744755
<listitem>
@@ -1869,6 +1880,17 @@ int SPI_execute_plan_extended(SPIPlanPtr <parameter>plan</parameter>,
18691880
</listitem>
18701881
</varlistentry>
18711882

1883+
<varlistentry>
1884+
<term><literal>bool <parameter>must_return_tuples</parameter></literal></term>
1885+
<listitem>
1886+
<para>
1887+
if <literal>true</literal>, raise error if the query is not of a kind
1888+
that returns tuples (this does not forbid the case where it happens to
1889+
return zero tuples)
1890+
</para>
1891+
</listitem>
1892+
</varlistentry>
1893+
18721894
<varlistentry>
18731895
<term><literal>uint64 <parameter>tcount</parameter></literal></term>
18741896
<listitem>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp