postgresql 是否可以为插入查询创建视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7316184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-20 23:16:42  来源:igfitidea点击:

Is it possible to create view for insert query

postgresqlview

提问by Laxminarayan Alas

i have created a table name "viewex"

我创建了一个表名“viewex”

create table viewex(
    sno int,
    name varchar(30),
    email varchar(30),
    address varchar(50),
    contact varchar(30)
);

Inserted data to the table.

向表中插入数据。

Now I am intrested to insert data only for 3 columns (name, address, contact):

现在我有兴趣仅为 3 列(姓名、地址、联系人)插入数据:

insert into viewex(name, address, contact) values('celcabs', 'good', 'bad');

Now the issue is.......... Is it possible to create the view for the query

现在的问题是.......是否可以为查询创建视图

insert into viewex(name, address, contact) values('celcabs', 'good', 'bad');

回答by Trygve Laugst?l

As of PostgreSQL 9.3 you can insert into and update "simple views": http://www.postgresql.org/docs/9.3/static/sql-createview.html

从 PostgreSQL 9.3 开始,您可以插入和更新“简单视图”:http: //www.postgresql.org/docs/9.3/static/sql-createview.html

回答by Brian Roach

What you're looking for is an updatable viewand postgresql doesn't have direct support for them.

您正在寻找的是 anupdatable view并且 postgresql 没有对它们的直接支持。

You can get the effect using CREATE RULE- that page has info on how to get the effect of an updatable view.

您可以使用CREATE RULE获得效果- 该页面包含有关如何获得可更新视图效果的信息。