Thread: BUG #17259: RETURN QUERY no longer accepts an UPDATE RETURNING

BUG #17259: RETURN QUERY no longer accepts an UPDATE RETURNING

From
PG Bug reporting form
Date:
The following bug has been logged on the website:

Bug reference:      17259
Logged by:          Jorge Gualtieri
Email address:      jorge@jrg.com.br
PostgreSQL version: 14.0
Operating system:   Ubuntu 20.04.3 LTS
Description:

In version 14.0 RETURN QUERY with UPDATE RETURNING in a function is
reporting an error and it works in version 13.4.
Test code:
--
create table test (i int primary key, j int);
insert into test values (1,1);


create or replace function f_test() returns setof int 
language plpgsql
as $fn$
begin 
    return query 
    update test
    set j = j+1
    where i = 1 
    returning j;

end;
$fn$;

select * from  f_test();
--
ERROR:  42601: query is not a SELECT
CONTEXT:  query: update test
        set j = j+1
        where i = 1
        returning j
PL/pgSQL function f_test() line 3 at RETURN QUERY
LOCATION:  exec_stmt_return_query, pl_exec.c:3571


Re: BUG #17259: RETURN QUERY no longer accepts an UPDATE RETURNING

From
Tom Lane
Date:
PG Bug reporting form <noreply@postgresql.org> writes:
> In version 14.0 RETURN QUERY with UPDATE RETURNING in a function is
> reporting an error and it works in version 13.4.

Thanks for the report!  This was already reported and repaired [1],
so it should be okay in 14.1.

            regards, tom lane

[1] https://www.postgresql.org/message-id/1F2F75F0-27DF-406F-848D-8B50C7EEF06A%40gmail.com