Re: Having trouble passing a shell variable to a query from psql command line

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Murthy Nunna <mnunna(at)fnal(dot)gov>
Cc: Pgsql-admin <pgsql-admin(at)lists(dot)postgresql(dot)org>
Subject: Re: Having trouble passing a shell variable to a query from psql command line
Date: 2025-08-29 17:58:03
Message-ID: CAKFQuwaAeF52LOpxjUUH0F3PN3w2CX8J-HJ=rV5wrzp1iyL=cQ@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-admin

On Fri, Aug 29, 2025 at 10:52 AM Murthy Nunna <mnunna(at)fnal(dot)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.

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Tom Lane 2025-08-29 18:16:21 Re: Having trouble passing a shell variable to a query from psql command line
Previous Message Murthy Nunna 2025-08-29 17:52:06 Having trouble passing a shell variable to a query from psql command line