I need to create a stored procedure which can take in the schema name and table name as the parameter and make an update on the same table.
CREATE OR REPLACE FUNCTION garscratch.update_table(schema_name text, table_name text ) RETURNS void as $$
DECLARE
table TEXT;
BEGIN
execute 'update '||schema||'.'||table_name|| 'set id = substring(id from 1 for 2) where name = "test"';
END;
$$ LANGUAGE plpgsql;
When I execute the procedure above as:
select update_table(my,my_table);
I get the error:
Column "my" does not exist.
It does not treat "my" as the schema name.