Limiting the occurence of a value in PostgreSQL
You can't access the fields of the new record dynamically using names stored in a variable. 

The only way I can think of, is to convert the NEW record into a JSON value, then you can access the value "dynamically" through the name: 

this_column_value := (to_jsonb(new) -&gt;&gt; this_column)::int; 
EXECUTE FORMAT('SELECT COUNT(*) FROM %I WHERE %I = $1', this_table, this_column)
  USING this_column_value
  INTO total;