Raw Table for which rule are stored in one table named md_formula , which are used to map in destination table
Drop/Create/Insert for raw_dbs_transacti
raw_dbs_transacti
For a dynamic query you need to use the 'execute' command.
EXECUTE dynamic-query-string INTO target-variable...
The manual page for this is here: http://www.postgresql.org/docs/current/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN
HTH