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

From Murthy Nunna
Subject Having trouble passing a shell variable to a query from psql command line
Date
Msg-id DM8PR09MB6677729E8FC7452DAAD053E5B83AA@DM8PR09MB6677.namprd09.prod.outlook.com
Whole thread Raw
Responses Re: Having trouble passing a shell variable to a query from psql command line
Re: Having trouble passing a shell variable to a query from psql command line
List pgsql-admin

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?

 

I appreciate any help you can provide.

pgsql-admin by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: pgAdmin 4 ?
Next
From: "David G. Johnston"
Date:
Subject: Re: Having trouble passing a shell variable to a query from psql command line