How do update a a specific column on some table where a given condition is fulfiled?

Viewed 104

I have a schema which contains the schema definition of all table, their name (internal_name) and an defined naming pattern. Each of these tables contains registrations, which utilizes this naming pattern, the naming pattern is usually a special concatenation of certain column value for a given row.

I am trying to make an update statement which both idenfies which tables need its names generates, and update them aswell.

I have so far come up with this (with some SO poking around)

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();

but I am not able to do this? I get an error in the string concatenation? why so?

0 Answers
Related