public inbox for [email protected]
help / color / mirror / Atom feedFrom: Torsten Förtsch <[email protected]>
To: Wiwwo Staff <[email protected]>
Cc: [email protected]
Subject: Re: Check psql parameter is passed, if not ask for it
Date: Mon, 5 Aug 2024 20:55:24 +0200
Message-ID: <CAKkG4_nWqk1DjxcBGorCBG9+Cdb2YHfSe16vzpEfQkKnkCsRMQ@mail.gmail.com> (raw)
In-Reply-To: <CAD1W9HXadWboboY+f4JVvMy8=hx-9POPskBoQq1T34AGofMPQQ@mail.gmail.com>
References: <CAD1W9HXadWboboY+f4JVvMy8=hx-9POPskBoQq1T34AGofMPQQ@mail.gmail.com>
to quote the documentation:
> If an unquoted colon (:) followed by a psql variable name appears within
an argument, it is replaced by the variable's value, as described in SQL
Interpolation below.
> The forms :'variable_name' and :"variable_name" described there work as
well. The :{?variable_name} syntax allows testing whether a variable is
defined. It is
> substituted by TRUE or FALSE. Escaping the colon with a backslash
protects it from substitution.
See https://www.postgresql.org/docs/16/app-psql.html
On Mon, Aug 5, 2024 at 8:46 PM Wiwwo Staff <[email protected]> wrote:
> 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
>
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Check psql parameter is passed, if not ask for it
In-Reply-To: <CAKkG4_nWqk1DjxcBGorCBG9+Cdb2YHfSe16vzpEfQkKnkCsRMQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox