我的问题很容易用一个例子来解释:我有一个“公共”模式(公共模式?),我在集群应用程序之间存储公共数据。
对于我的应用程序的每个实例,我都有一个角色(用作应用程序用户)。而且我有一个共同的角色,app_users
拥有read-only
共同模式的特权,并且每个应用程序角色都是一个member
。app_users
现在我的问题是:如何在 app_a 方案上设置触发器,以执行通用方案中的函数(过程),但影响(且仅影响)app_a 表?
我是说:
// common_scheme, dummy function to emulate the mysql on update = now()
CREATE OR REPLACEFUNCTION update_etime() RETURNS TRIGGER AS $$
BEGIN
NEW.etime = date_part('epoch'::text, now())::int;
RETURN NEW;
END;
$$ language plpgsql;
// now, in the app_foo scheme, i have the table:
CREATE TABLE foo_table (fid serial not null primary key unique, label char(25));
// and the trigger:
CREATE TRIGGER foo_table_update_etime BEFORE UPDATE ON foo_talbe FOR EACH ROW EXECUTE PROCEDURE update_etime();
// ERROR: function update_etime() does not exist
CREATE TRIGGER foo_table_update_etime BEFORE UPDATE ON foo_talbe FOR EACH ROW EXECUTE PROCEDURE common_scheme.update_etime();
// ERROR: function common_scheme.update_etime() does not exist
将访问 app_foo 的用户对 common_schema 中的 update_etime() 函数具有执行权限。
任何想法?
我已经四处搜索,但我找到从其他模式调用函数的唯一解决方案是类似的,execute 'select * from ' || schema_name || '.table_name';
但我认为这在我的情况下不会起作用,因为该函数必须与“本地”方案一起使用。