Check psql parameter is passed, if not ask for it - Mailing list pgsql-general

From Wiwwo Staff
Subject Check psql parameter is passed, if not ask for it
Date
Msg-id CAD1W9HXadWboboY+f4JVvMy8=hx-9POPskBoQq1T34AGofMPQQ@mail.gmail.com
Whole thread Raw
Responses Re: Check psql parameter is passed, if not ask for it
List pgsql-general
Hi!
I want to check if I pass the parameter "param1" to a sql script "delme.sql" like
```
\if ':param1'
  \echo :param1;
\else
  \prompt 'Param1? ' :param1
\endif
select :'param1';
```
if parameter `param1` is not passed, the .sql should ask for it.

If I run something like
`psql -f delme.sql -v param1=1`
it works, but if i pass
`psql -f delme.sql -v param1=meh`
i receive
`psql:delme.sql:1: error: unrecognized value ":param1" for "\if expression": Boolean expected`

How can I implement that?
TIA, Wiwwo

pgsql-general by date:

Previous
From: Dominique Devienne
Date:
Subject: Re: UPDATE-FROM and INNER-JOIN
Next
From: Torsten Förtsch
Date:
Subject: Re: Check psql parameter is passed, if not ask for it