Hi.
While working on updating the patch for the bug reported below:
https://www.postgresql.org/message-id/flat/CAFYwGJ0xfzy8jaK80hVN2eUWr6huce0RU8AgU04MGD00igqkTg%40mail.gmail.com
I noticed that the EXCLUDED pseudo-relation allows accessing columns that,
ISTM, should rather be inaccessible.
Example:
create table foo (a int unique, b text);
create view foo_view as select b, a+1 as c, a from foo;
explain insert into foo_view (a, b) select 1, 2 on conflict (a) do update
set b = excluded.b where excluded.c > 0;
The excluded.c above should result in an error, because it is impossible
for a user to specify a value for it, as shown below:
insert into foo_view (a, b, c) select 1, 2, 3 on conflict (a) do update
set b = excluded.b where excluded.c > 0;
ERROR: cannot insert into column "c" of view "foo_view"
DETAIL: View columns that are not columns of their base relation are not
updatable
IOW, the EXCLUDED pseudo-relation should only allow referencing the
columns present in the underlying physical relation. Thoughts?
Thanks,
Amit