I'd like to pass a parameter to an anonymous PL/pgSQL
block via psql
command line, then check that parameter in a conditional.
The relevant part of the SQL is here:
do $$
begin
if (':para' = 1) then
-- statements;
end if;
end $$
;
I call this script as such:
psql -d dbname -v para=1 < script.sql
I receive the error:
ERROR: invalid input syntax for integer: ":para"
LINE 1: SELECT (':para' = 1)
^
QUERY: SELECT (':para' = 1)
CONTEXT: PL/pgSQL function inline_code_block line 3 at IF
I tried using the case/when paradigm, which did not work either.
I am guessing that a psql
parameter is not compatible with PL/pgSQL? Ultimately, my goal is to run a single delete
statement if I pass 1
as a psql
parameter, and not run it if I pass 0
.