How can I pass table reference to the function? I tried following code but I'm getting errors:
CREATE OR REPLACE FUNCTION merge_(text,n VARCHAR(32),s VARCHAR(32),val int) RETURNS VOID AS
$$
DECLARE
_table ALIAS FOR $1;
BEGIN
RAISE NOTICE '_table = %', _table;
...
SELECT merge_('testtable','h','a',50000);
NOTICE: _table = testtable
This works fine, but when I try to execute a command I get an error:
CREATE OR REPLACE FUNCTION merge_(text,n VARCHAR(32),s VARCHAR(32),val int) RETURNS VOID AS
$$
DECLARE
_table ALIAS FOR $1;
BEGIN
UPDATE _table ....
ERROR: relation "_table" does not exist