I am trying to pass two variables in to a .psql file that I am running via psql from the command line. One of my variables converts to the value the other does not. var1 (the id value near the end of the statement in near the where clause is converted fine but var2 the variable that is part of the json check of id is not converted. I assume it is something related to how I am escaping things but after a good hour playing with this I am stuck. Thanks
Command Line
psql -h 127.0.0.1 -f "delete.psql" -v var1="$var1" -v var2="$var2"
delete.sql
update data
set value = jsonb_set(value, '{my_items}',
jsonb_path_query_array(value->'item', '$ ? (@."id" <> (:'var2') )')) where id=(:'var1') ;
Error that I get back because of the lack of conversion of var2
psql:delete.psql:3: ERROR: syntax error at or near "var2"
LINE 3: ...th_query_array(value->'my_items', '$ ? (@."id" <> (:'var2')...
^