postgresql - PostgreSQL 触发器与 LibreOffice Base 前端
问题描述
我在 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
(出于组织政治原因,此数据库目前使用自然键。)Bound 字段设置为 0,即显示的主键列。
所以...... 2个问题:
- 为什么这个问题只发生在 Base 中,我该如何解决它(或者至少更好地解决它)?
- 由于 Bound 字段似乎只采用一个整数,这实际上是否意味着您不能将列表框用于具有多列主键的表,至少如果有一个显示的列?
解决方案
在触发函数中,可以完全限定表
...
and new.name not in (select viewable_item from viewing.sourcing)
...
推荐阅读
- django - 如何在 HTML 页面上预填充 Django 动态添加的表单集字段
- eclipse - 从 Git 导入的 Eclipse 动态 web 项目:无法解析导入 XXX
- ios - SwiftUI | 如何覆盖 viewWillAppear 等生命周期方法
- splunk - 是否可以制作动态 splunk 仪表板?
- ruby - 在 Ruby on Rails 中将多态关联与 STI 或 MTI 混合
- c++ - 动态改变数组的大小并读入值。(无载体)
- javascript - onclick 按钮仅显示一次 toastr 并将错误消息分组到 toastr
- javascript - 如何在 Spring MVC 中处理 Javascript 对象数组?
- reactjs - 未处理的 Promise Rejection TypeError B.setState is not a Function
- c++ - OpenCV QT,显示视频帧(不使用 While 循环)