Re: oversight in EphemeralNamedRelation support

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>
Cc: Julien Rouhaud <rjuju123(at)gmail(dot)com>, PG Hackers <pgsql-hackers(at)postgresql(dot)org>, Hugo Mercier <hugo(dot)mercier(at)oslandia(dot)com>, Kevin Grittner <kgrittn(at)gmail(dot)com>
Subject: Re: oversight in EphemeralNamedRelation support
Date: 2017-10-12 21:01:48
Message-ID: 32680.1507842108@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com> writes:
> On Fri, Oct 13, 2017 at 8:50 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Hm. I actually think the bug here is that 18ce3a4ab introduced
>> anything into setTargetTable at all. There was never previously
>> any assumption that the target could be anything but a regular
>> table, so we just ignored CTEs there, and I do not think the
>> new behavior is an improvement.

> Before that, CTE used as modify targets produced a different error message:

> postgres=# WITH d AS (SELECT 42) INSERT INTO d VALUES (1);
> ERROR: relation "d" does not exist
> LINE 1: WITH d AS (SELECT 42) INSERT INTO d VALUES (1);
> ^

Well, I think that is a poorly chosen example. Consider this instead:
pre-v10, you could do this:

regression=# create table mytable (f1 int);
CREATE TABLE
regression=# with mytable as (select 1 as x) insert into mytable values(1);
INSERT 0 1
regression=# select * from mytable;
f1
----
1
(1 row)

The CTE was simply not part of the available namespace for the INSERT's
target, so it found the regular table instead. v10 has thus broken
cases that used to work. I think that's a bug.

There may or may not be a case for allowing ENRs to capture names that
would otherwise refer to ordinary tables; I'm not sure. But I see very
little case for allowing CTEs to capture such references, because surely
we are never going to allow that to do anything useful, and we have
several years of precedent now that they don't capture.

I think we need to either remove that call from setTargetTable entirely,
or maybe adjust it so it can only find ENRs not CTEs.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2017-10-12 21:18:25 Re: UPDATE of partition key
Previous Message Andres Freund 2017-10-12 20:55:55 Re: show precise repos version for dev builds?