首页 > 解决方案 > 如何在满足给定条件的某个表上更新特定列?

问题描述

我有一个架构,其中包含所有表的架构定义、它们的名称(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();

但我无法做到这一点?我在字符串连接中遇到错误?为什么这样?

标签: postgresql

解决方案


推荐阅读