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

From David G. Johnston
Subject Re: Having trouble passing a shell variable to a query from psql command line
Date
Msg-id CAKFQuwaAeF52LOpxjUUH0F3PN3w2CX8J-HJ=rV5wrzp1iyL=cQ@mail.gmail.com
Whole thread Raw
In response to Having trouble passing a shell variable to a query from psql command line  (Murthy Nunna <mnunna@fnal.gov>)
Responses Re: Having trouble passing a shell variable to a query from psql command line
List pgsql-admin
On Fri, Aug 29, 2025 at 10:52 AM Murthy Nunna <mnunna@fnal.gov> wrote:


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? 

 

I appreciate any help you can provide.


I provide the documentation.  Under psql -c:

"command must be either a command string that is completely parsable by the server (i.e., it contains no psql-specific features)"

Variable-substitution is a psql-specific feature.

David J.

pgsql-admin by date:

Previous
From: Murthy Nunna
Date:
Subject: Having trouble passing a shell variable to a query from psql command line
Next
From: Tom Lane
Date:
Subject: Re: Having trouble passing a shell variable to a query from psql command line