That's possible, but the USING clause of EXECUTE can only pass values.
While identifiers like table and column names must be concatenated (be wary of SQL injection!) before executing the command. Using format() (Postgres 9.1+) it could work like this:
$$
DECLARE
_command text := 'UPDATE %I SET %I = $1 WHERE ....'; -- add WHERE condition
_col text := 'votes';
BEGIN
EXECUTE format(_command, 'anotherTable', _col)
USING NEW.myColumn;
END
$$;
Fixed a couple of minor problems in passing.
It must be mentioned that NEW is only available in trigger functions.
Be aware that 'anotherTable' is case sensitive here (being converted and escaped from a string), while NEW.myColumn is not (processed as identifier). Use legal, lower case, unquoted identifiers in Postgres to make your life easier.
Related answers with more explanation and links:
To dynamically extract a column value from a NEW record by column name.
... you can use the hstore #= operator:
Or you can make it work with standard features of dynamic SQL as well:
$$
DECLARE
_col text := 'votes';
_new_col text := 'column_name_in_new'; -- enter column name here, case sensitive
BEGIN
EXECUTE format(
'UPDATE %I SET %I = $1.%I WHERE ... ' -- add WHERE condition
, 'anotherTable', _col, _new_col)
USING NEW; -- pass whole row
END
$$;
Related: