可更新的 VIEW 不适用于 Postgres 9.5 中的 ON CONFLICT
Updatable VIEW doesn't work with ON CONFLICT in Postgres 9.5
PostgreSQL 版本:9.5.4
我有一个 table 定义为:
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)
);
我的视图定义为:
create or replace view test as select * from test_1 with cascaded check
option;
当应用程序代码是
通过视图名称工作(在需要时通过替换 table 来实现一种简单的分区)
当我 运行 在 view 上进行以下查询时:
insert into test (c1, c2, c3) values (decode('MTIzAAE=', 'base64'), 'text', true) on conflict (c1, c2) do update set c3=excluded.c3
我收到以下错误:
[0A000] ERROR: ON CONFLICT is not supported on table "test" used as a catalog table
Position: 83
但是对 table 的相同查询按预期工作。根据 Postgres 文档,这应该也适用于视图,因为 ON CONFLICT 完全支持 updatable views https://www.postgresql.org/docs/9.5/static/sql-createview.html
知道我错过了什么吗?
显然,使用 with check option
的视图不支持此功能
如果您删除 with cascaded check option
这有效。
这在手册中没有明确提及,因此这可能是文档疏忽。
PostgreSQL 版本:9.5.4
我有一个 table 定义为:
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)
);
我的视图定义为:
create or replace view test as select * from test_1 with cascaded check
option;
当应用程序代码是 通过视图名称工作(在需要时通过替换 table 来实现一种简单的分区)
当我 运行 在 view 上进行以下查询时:
insert into test (c1, c2, c3) values (decode('MTIzAAE=', 'base64'), 'text', true) on conflict (c1, c2) do update set c3=excluded.c3
我收到以下错误:
[0A000] ERROR: ON CONFLICT is not supported on table "test" used as a catalog table
Position: 83
但是对 table 的相同查询按预期工作。根据 Postgres 文档,这应该也适用于视图,因为 ON CONFLICT 完全支持 updatable views https://www.postgresql.org/docs/9.5/static/sql-createview.html
知道我错过了什么吗?
显然,使用 with check option
如果您删除 with cascaded check option
这有效。
这在手册中没有明确提及,因此这可能是文档疏忽。