Re: Having trouble passing a shell variable to a query from psql command line - Mailing list pgsql-admin

From Tom Lane
Subject Re: Having trouble passing a shell variable to a query from psql command line
Date
Msg-id 2343915.1756494912@sss.pgh.pa.us
Whole thread Raw
In response to Re: Having trouble passing a shell variable to a query from psql command line  (Ron Johnson <ronljohnsonjr@gmail.com>)
Responses Re: Having trouble passing a shell variable to a query from psql command line
List pgsql-admin
Ron Johnson <ronljohnsonjr@gmail.com> 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



pgsql-admin by date:

Previous
From: Murthy Nunna
Date:
Subject: RE: Having trouble passing a shell variable to a query from psql command line
Next
From: Ron Johnson
Date:
Subject: Why might autovacuum not be analyzing chk_image_rp4_y2025m08?