From: Petr Fedorov <petr.fedorov@phystech.edu>
To: pgsql-bugs@postgresql.org
Subject: 'update returning *' returns 0 columns instead of empty row with 2 columns when (i) no rows updated and (ii) when applied to a partitioned table with sub-partition
Date: Fri, 1 Feb 2019 17:32:43 +0300
Message-ID: <5da6f0f0-1364-1876-6978-907678f89a3e@phystech.edu> (raw)
Hello,
The following code snippet demonstrates the problem: the first select
passes and the second [select * from testf(FALSE)] fails. I would expect
that select * from testf(...); works without errors in both cases.
begin;
create table test (id integer, data char(1)) partition by list (id)
tablespace pg_default;
create table test_1 partition of test for values in (1) partition by
list (data);
create table test_1_a partition of test_1 for values in ('a');
create function testf(p boolean) returns setof test language 'plpgsql'
as $body$ begin return query update test set id=id where p returning *;
end; $body$;
insert into test (id, data) values (1, 'a');
select * from testf(TRUE);
select * from testf(FALSE);
rollback;
The result:
ERROR: structure of query does not match function result type
SQL state: 42804
Detail: Number of returned columns (0) does not match expected column
count (2).
Context: PL/pgSQL function testf(boolean) line 1 at RETURN QUERY
I'm on PostgreSQL 11.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC)
4.8.5 20150623 (Red Hat 4.8.5-28), 64-bit on Centos 7
uname -a gives Linux 3.10.0-862.11.6.el7.x86_64 #1 SMP Tue Aug 14
21:49:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: petr.fedorov@phystech.edu
Subject: Re: 'update returning *' returns 0 columns instead of empty row with 2 columns when (i) no rows updated and (ii) when applied to a partitioned table with sub-partition
In-Reply-To: <5da6f0f0-1364-1876-6978-907678f89a3e@phystech.edu>
References: <5da6f0f0-1364-1876-6978-907678f89a3e@phystech.edu>
* 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