Updatable VIEW doesn't work with ON CONFLICT in Postgres 9.5

旧城冷巷雨未停 提交于 2019-12-12 20:03:10

问题


PostgreSQL version: 9.5.4

I have a table defined as:

CREATE TABLE IF NOT EXISTS TEST_1 (
ID       SERIAL PRIMARY KEY,
C1       BYTEA,
C2       TEXT NOT NULL,
C3       BOOLEAN NOT NULL DEFAULT FALSE,
CONSTRAINT TEST_1_unique_idx UNIQUE(C1, C2)
);

I have a view defined as:

create or replace view test as select * from test_1 with cascaded check
option;

This is necessary to abstract from table name while application code is working via view name (to implement a kind of simple partitioning with replacing tables when needed)

When I run the following query on view:

insert into test (c1, c2, c3) values (decode('MTIzAAE=', 'base64'), 'text', true) on conflict (c1, c2) do update set c3=excluded.c3

I get the following error:

[0A000] ERROR: ON CONFLICT is not supported on table "test" used as a catalog table
  Position: 83

But the same query on table works as expected. According to Postgres documentation this should work with view as well since ON CONFLICT is fully supported with updatable views https://www.postgresql.org/docs/9.5/static/sql-createview.html

Any ideas what am I missing?


回答1:


Apparently this is not supported for views that use with check option

If you remove with cascaded check option this works.

This is not explicitly mentioned in the manual, so this might be a documentation oversight.



来源:https://stackoverflow.com/questions/40260920/updatable-view-doesnt-work-with-on-conflict-in-postgres-9-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!