public inbox for [email protected]
help / color / mirror / Atom feedFrom: Ron Johnson <[email protected]>
To: Pgsql-admin <[email protected]>
Subject: Re: Having trouble passing a shell variable to a query from psql command line
Date: Fri, 29 Aug 2025 14:27:49 -0400
Message-ID: <CANzqJaBC5rx0fNbmx1bom9ZE3v1UgQxH3uXWOFHCfUb=rkqcEQ@mail.gmail.com> (raw)
In-Reply-To: <DM8PR09MB6677729E8FC7452DAAD053E5B83AA@DM8PR09MB6677.namprd09.prod.outlook.com>
References: <DM8PR09MB6677729E8FC7452DAAD053E5B83AA@DM8PR09MB6677.namprd09.prod.outlook.com>
On Fri, Aug 29, 2025 at 1:52 PM Murthy Nunna <[email protected]> wrote:
> Hello,
>
>
>
> Below works:
>
>
>
> psql -d mydb -t -A -c "SELECT relkind FROM pg_class WHERE relname =
> 'pg_trigger' ;"
>
> r
>
>
>
> I am getting syntax error from following:
>
>
>
> echo $SHELL_VAR
>
> pg_trigger
>
>
>
> psql -d mydb -t -A -c "SELECT relkind FROM pg_class WHERE relname =
> :'SHELL_VAR' ;" -v SHELL_VAR="$SHELL_VAR"
>
> ERROR: syntax error at or near ":"
>
> LINE 1: SELECT relkind FROM pg_class WHERE relname = :'SHELL_VAR' ;
>
> ^
>
> Is psql script necessary to pass shell variable?
>
Yeah. From the cli KISS and do regular bash variable string expansion.
psql -d mydb -tAc "SELECT relkind FROM pg_class WHERE relname =
${SHELL_VAR} ;"
--
Death to <Redacted>, and butter sauce.
Don't boil me, I'm still alive.
<Redacted> lobster!
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]
Subject: Re: Having trouble passing a shell variable to a query from psql command line
In-Reply-To: <CANzqJaBC5rx0fNbmx1bom9ZE3v1UgQxH3uXWOFHCfUb=rkqcEQ@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