public inbox for [email protected]  
help / color / mirror / Atom feed
From: Tom Lane <[email protected]>
To: Ron Johnson <[email protected]>
Cc: Pgsql-admin <[email protected]>
Subject: Re: Having trouble passing a shell variable to a query from psql command line
Date: Fri, 29 Aug 2025 15:15:12 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <CANzqJaBC5rx0fNbmx1bom9ZE3v1UgQxH3uXWOFHCfUb=rkqcEQ@mail.gmail.com>
References: <DM8PR09MB6677729E8FC7452DAAD053E5B83AA@DM8PR09MB6677.namprd09.prod.outlook.com>
	<CANzqJaBC5rx0fNbmx1bom9ZE3v1UgQxH3uXWOFHCfUb=rkqcEQ@mail.gmail.com>

Ron Johnson <[email protected]> writes:
> 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} ;"

This isn't a great recommendation because bash is not aware of
SQL's quoting rules.  It'll work in simple cases, but there's
a risk of SQL injection if the value of SHELL_VAR comes from
an untrustworthy source.

			regards, tom lane





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: Having trouble passing a shell variable to a query from psql command line
  In-Reply-To: <[email protected]>

* 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