在视图上执行触发器? [英] Execute Trigger on View?

查看:77
本文介绍了在视图上执行触发器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对数据库触发器和/或视图不太熟悉。我目前正在使用PostgreSQL和HSQL;尽管数据库不是太重要。我只是想知道任何数据库是否提供这样的信息:

I am not too familiar with database triggers and/or views. I am currently using PostgreSQL and HSQL; although the database is not too important. I am just wondering if any database offers something like this:

我有一个(示例)表,例如:

I have an (example) table like this:

CREATE TABLE DUMMY_TABLE (ID INTEGER, NUMBER INTEGER);

我创建了这样的视图:

CREATE VIEW DUMMY_VIEW AS SELECT * FROM DUMMY_TABLE WHERE NUMBER > 5;

我插入几个实体:

INSERT INTO DUMMY_TABLE VALUES(1,2);
INSERT INTO DUMMY_TABLE VALUES(1,10);

因此,当我打电话时,DUMMY_VIEW当然只包含VALUES(1,10)

so of course the DUMMY_VIEW only contains VALUES(1,10) when I call

SELECT * FROM DUMMY_VIEW

所以现在我想做的是将触发器添加到DUMMY_VIEW中,只要插入具有NUMBER> 5的实体,就会调用该触发器。

So now what I want to do is add a trigger to the DUMMY_VIEW that is called whenever an entity is inserted that has NUMBER > 5.

我尝试添加触发器直接到HSQL和PostgreSQL中的DUMMY_VIEW;

I have tried adding triggers directly to the DUMMY_VIEW in both HSQL and PostgreSQL; but they say that triggers cannot be added to views.

这(或功能上类似的解决方案)是否可能?

Is this (or a functionally similar solution) possible?

推荐答案

应注意,PostgreSQL 9.1+支持视图触发器。参见等待9.1 –简短地查看

It should be noted that PostgreSQL 9.1+ supports triggers on views. See WAITING FOR 9.1 – TRIGGERS ON VIEWS for a brief look at this.

这篇关于在视图上执行触发器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆