How do I create dynamic column names, that can be used in a trigger? I have a trigger function, that should update a value in a table. The columnname is created dynamicially. But when I run it, the error does not grasp the column name but instead the name of the variable. What the code should do was to create a column name example: p123
ERROR: column "column_name" of relation "col_extra_val_lookup" does not exist LINE 2: SET column_name = NEW.value
The code I use is this:
DECLARE
column_name TEXT ;
BEGIN
column_name :='p'|| NEW.customer_column_id;
UPDATE col_extra_val_lookup
SET column_name = NEW.value
WHERE col_extra_val_lookup.customer_id=NEW.customer_id;
END