I want to create a trigger which will made selected attribute (given as a parameter) uppercase on first letter and lowercase on the remaining.
I would like to write it in similar way to this non-working code:
CREATE OR REPLACE FUNCTION myTrigger() RETURNS trigger AS
$BODY$
DECLARE
colname TEXT;
newContent TEXT;
BEGIN
colname = TG_ARGV[0];
newContent = format('SELECT ( CONCAT(UPPER(LEFT(NEW.%I,1)),LOWER(SUBSTRING(NEW.%I,2,LENGTH(NEW.%I)))) )', colname, colname, colname);
EXECUTE newContent INTO format('NEW.%I', colname);
RETURN NEW;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
Why isn't it possible to EXECUTE prepared statement inside of the trigger just like in the console?
create triggerstatement?INTO format(...)format is not a variable. Trigger statement isCREATE TRIGGER myTrigger BEFORE INSERT OR UPDATE ON test FOR EACH ROW EXECUTE PROCEDURE myTrigger('sname');