gpt4 book ai didi

sql - 插入到简单的 Postgres View 中

转载 作者:行者123 更新时间:2023-11-29 11:47:53 25 4
gpt4 key购买 nike

<分区>

Postgres documentation

Simple views are automatically updatable: the system will allow INSERT, UPDATE and DELETE statements to be used on the view in the same way as on a regular table.

然后它列出了一些要求。我相信我的 View 满足所有这些要求,但如果我尝试插入该 View ,我会收到错误消息:

psql:C355A12.txt:1702: ERROR:  cannot insert into a view
HINT: You need an unconditional ON INSERT DO INSTEAD rule.

我要插入的 View 定义为:

CREATE VIEW locationsView
AS SELECT lc_name, lc_min, lc_max, lc_sizeX, lc_sizeY
FROM locations;

这是表定义:

CREATE TABLE locations(
lc_name LocationName NOT NULL,
lc_min LocationMin NOT NULL
DEFAULT 0,
lc_max LocationMax NOT NULL
DEFAULT 0,
lc_sizeX LocationSizeX NOT NULL,
lc_sizeY LocationSizeY NOT NULL,
PRIMARY KEY (lc_name)
);

使用的域是:

CREATE DOMAIN LocationName AS TEXT;
CREATE DOMAIN LocationMin AS INT;
CREATE DOMAIN LocationMax AS INT;
CREATE DOMAIN LocationSizeX As INT;
CREATE DOMAIN LocationSizeY As INT;

我如何获得文档描述的这种“自动更新”特性?

我使用的是 Postgres 版本 9.3.4。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com