Reputation: 1547
We can use NEW.columnname
and we get it's value.
Can I use NEW
variable as array to get it's values? like NEW[1]
or NEW.1
...Or if I pass column names in one text array to trigger function argument then can I use NEW.$1
to get 1st column value?
I have to do it only with language plpgsql
Upvotes: 1
Views: 1847
Reputation: 78433
I've suggested a dup question, since it's really the same underlying issue.
I'd be quite enthusiastic to be shown wrong (I occasionally need this myself too), but best I'm aware, referring column names using variables is one of those cases where you actually need to use PL/C triggers rather than PL/PgSQL triggers. You'll find examples of such triggers in contrib/spi and on PGXN.
Alternatively, write a function that writes your trigger using execute
statements.
Upvotes: 0