postgresql - 如何在满足给定条件的某个表上更新特定列?
问题描述
我有一个架构,其中包含所有表的架构定义、它们的名称(internal_name)和定义的命名模式。这些表中的每一个都包含使用这种命名模式的注册,命名模式通常是给定行的特定列值的特殊连接。
我正在尝试制作一个更新语句,它既可以识别哪些表需要生成其名称,也可以更新它们。
到目前为止,我已经想出了这个(有一些 SO 闲逛)
DROP TRIGGER entry_name ON public.entity;
-- Create Trigger functions
CREATE OR REPLACE FUNCTION registration_entry_name() RETURNS trigger AS $registration_entry_name$
DECLARE
result text;
BEGIN
UPDATE B.internal_name'||_registration||' -- the table the contains each registration
Set entry_name = 'new_name' -- some new name
FROM entity as B -- entity being the schema table containig the definitions.
WHERE NEW.naming_pattern <> OLD.naming_pattern;
END;
$registration_entry_name$ LANGUAGE plpgsql;
CREATE TRIGGER entry_name BEFORE INSERT OR UPDATE ON public.entity
FOR EACH ROW EXECUTE PROCEDURE registration_entry_name();
但我无法做到这一点?我在字符串连接中遇到错误?为什么这样?
解决方案
推荐阅读
- architecture - 这会是双状态机吗?
- azure - 监视 Azure 基本内部负载均衡器
- postgresql - 如何在 PostgreSQL 中将十进制转换为 isnull 时修复语法错误?
- ios - Swift 中的图像过滤器
- php - Paypal NVP SOAP(经典 api),一切看起来都很好,但没有到账
- python - 如何检查字符串是否由 Python 中给定字符以外的字符组成?
- java - 无法解析符号“FirebaseRecyclerOptions”
- git - 如何从 master 克隆,从而通过远程分支以及我的本地目录进行更新?
- excel - 保存路径不存在时的宏错误处理
- javascript - 当存在多个字段时,提交按钮不起作用