I have a bat file which have below command
"C:\Program Files (x86)\pgAdmin III\1.22\psql" -U postgres -h hostname -p 5432 -d TestDB -w -f 1.1.sql -v num_var=1.2
this command calls file 1.1.sql which have below script
DO $$
Begin
If Exists (Select * from pg_statio_user_tables where relname = 'applicationsetting' ) then
update applicationsetting set value = :num_var
where applicationsettingid = '32bdba3b-39f6-4e43-947e-0bfdd4f5d561';
End IF;
End $$;
while clicking on bat file, I am getting this error
psql:1.1.sql:9: ERROR: syntax error at or near ":"
LINE 4: update demo set keyvalue = :num_var
However, the code works fine if I don't pass any variable and use static value in the update query.
EDIT
Code also works fine if I use the update query only without DO block and if clause.