我有以下触发器函数&PostgreSQL 12.1:中的触发器
create or replace function constraint_for_present()
returns trigger
as $$
BEGIN
if
new.present_status = 'viewing'
and new.name not in (select viewable_item from sourcing)
then raise exception 'a present_status of "viewing" requires that the viewable item is in sourcing';
end if;
return new;
END;
$$ language plpgsql;
create trigger constraint_for_present
before insert or update of present_status on viewable_item
for each row
execute function constraint_for_present();
在psql和TablePlus客户端的数据输入过程中,这些功能可以正常工作。但是,函数在通过LibreOffice Base:访问数据库时抛出错误
pq_driver: [PGRES_FATAL_ERROR]ERROR: relation "sourcing" does not exist
LINE 2: and new.name not in (select viewable_item from sourcing)
QUERY: SELECT new.present_status = 'viewing'
and new.name not in (select viewable_item from sourcing)
CONTEXT: PL/pgSQL function viewing.constraint_for_present() line 3 at IF
(caused by statement 'UPDATE "viewing"."viewable_item" SET "present_status" = 'none' WHERE "name" = 'test4'')
在Base中,我为触发器的表设置了一个简单的表单,每个外键列都设置为列表框,列表内容的类型设置为Sql(也尝试过Sql[Native](。每个的列表内容是(带有适当的表和主键列(:
select name from viewing.cv_present_status order by name
(出于组织政治原因,此数据库目前使用自然键。("绑定"字段设置为0,这是显示的主键列。
所以。。。2个问题:
- 为什么这个问题只发生在Base中,我该如何解决它(或者至少更好地解决它(
- 由于"绑定"字段似乎只接受一个整数,这实际上是否意味着您不能为具有多列主键的表使用列表框,至少在有单个显示列的情况下是这样
在触发器函数中,您可以完全限定表
...
and new.name not in (select viewable_item from viewing.sourcing)
...