From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Peter Eisentraut <peter(dot)eisentraut(at)enterprisedb(dot)com> |
Cc: | Vitaly Ustinov <vitaly(at)ustinov(dot)ca>, pgsql-bugs(at)lists(dot)postgresql(dot)org |
Subject: | Re: Generated column is not updated (Postgres 13) |
Date: | 2021-05-20 01:55:48 |
Message-ID: | 3569485.1621475748@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
I wrote:
> ... I think we ought
> to disallow the case instead. I observe that we already disallow
> generated columns depending on each other: ...
> But a whole-row var violates this concept completely: it makes the
> generated column depend, not only on every other column, but on itself
> too. Also, even if you don't mind null-for-not-yet-computed-value,
> that would expose the computation order of the generated columns.
After actually looking at the code involved, I'm even more on the
warpath. Not only is it failing to reject whole-row vars, but it's
failing to reject system columns. That is (a) infeasible to support,
given that we don't know the values of the system columns at the time
we compute generated expressions, and (b) just plain ludicrous in
expressions that are required to be immutable.
I see that there is actually a regression test case that believes
that "tableoid" should be allowed, but I think that is nonsense.
In the first place, it's impossible to claim that tableoid is an
immutable expression. Consider, say, "tableoid > 30000". Do you
think such a column is likely to survive dump-and-reload unchanged?
Also, while that example is artificial, I'm having a hard time
coming up with realistic immutable use-cases for generation
expressions involving tableoid.
In the second place, there are a bunch of implementation dependencies
that we'd have to fix if we want to consider that supported. I think
it's mostly accidental that the case seems to work in the mainline
INSERT code path. It's not hard to find cases where it does not work,
for example
regression=# create table foo (f1 int);
CREATE TABLE
regression=# insert into foo values (1);
INSERT 0 1
regression=# alter table foo add column f2 oid GENERATED ALWAYS AS (tableoid) STORED;
ALTER TABLE
regression=# table foo;
f1 | f2
----+----
1 | 0
(1 row)
So I think we should just forbid tableoid along with other system
columns, as attached.
regards, tom lane
Attachment | Content-Type | Size |
---|---|---|
disallow-wholerow-and-system-cols-in-GENERATED.patch | text/x-diff | 4.8 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Paquier | 2021-05-20 02:18:55 | Re: BUG #17023: wal_log_hints not configured even if it on |
Previous Message | Peter Geoghegan | 2021-05-20 01:55:45 | Re: Fwd: BUG #17017: Two versions of the same row of records are returned in one query |