From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | exclusion(at)gmail(dot)com |
Cc: | pgsql-bugs(at)lists(dot)postgresql(dot)org, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com> |
Subject: | Re: BUG #18546: Attempt to insert default into a non-updatable column of a view fails with a dubious error |
Date: | 2024-07-20 16:26:29 |
Message-ID: | 320614.1721492789@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-bugs |
PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> The following query:
> CREATE TABLE t (a int);
> CREATE VIEW v AS SELECT a, a + 0 AS a0 FROM t;
> INSERT INTO v values (default, default);
> raises
> ERROR: XX000: attribute number 2 not found in view targetlist
> LOCATION: adjust_view_column_set, rewriteHandler.c:3045
> Whilst
> INSERT INTO v values (default, 1);
> fails with clearer
> ERROR: 0A000: cannot insert into column "a0" of view "v"
> DETAIL: View columns that are not columns of their base relation are not
> updatable.
Interesting. I thought this was a wrong-order-of-checks problem,
but it's more subtle than that. The "cannot insert into column "a0""
message is produced when view_cols_are_auto_updatable recognizes that
we can't assign to that particular column. But
view_cols_are_auto_updatable doesn't test the a0 column, because
it's told to check the columns that are targeted by the query
targetlist after rewriteTargetListIU ... and rewriteTargetListIU has
thrown away the DEFAULT markers, on the grounds that the column
defaults are null and we don't need to represent that explicitly.
The existing code/comments (dating AFAICS to Dean's cab5dc5da)
already point out that rewriteTargetListIU can add targetlist items,
but we missed the fact that it can delete them too. So it seems like
what we need to do is union the original set of target columns with
what's listed in the targetlist, as attached. I suppose we could
also rethink the decision to throw away null defaults, but that seems
much more invasive.
Thanks for the report!
regards, tom lane
Attachment | Content-Type | Size |
---|---|---|
fix-bug-18546.patch | text/x-diff | 5.0 KB |
From | Date | Subject | |
---|---|---|---|
Next Message | PG Bug reporting form | 2024-07-20 22:12:30 | BUG #18547: bemused by your unhelpful installation guides |
Previous Message | PG Bug reporting form | 2024-07-20 09:00:01 | BUG #18546: Attempt to insert default into a non-updatable column of a view fails with a dubious error |