I am running a sql query from the command line where I pass in value called tablename:
psql "hostname" -v tablename=$1 -a -q -f "filename.sql"
I then set the variable like this:
\set tablename :tablename
And then I have a function where I want to use the variable tablename like this:
DO $$
BEGIN
if (tablename = 'movie_table') then
-- query goes in here
END if;
END;
$$;
I have also tried declaring the variable with a few variations of this:
DECLARE tablename varchar := :tablename;
Please let me know if you have any suggestions. I get the following error:
syntax error at or near ":"