Syntax error when combining --set and --command has me stumped

From: Ron <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Syntax error when combining --set and --command has me stumped
Date: 2022-07-28 19:40:06
Message-ID: 352ceea1-029d-726e-89b5-74be4946e67b@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


$ alias psql12
alias psql12='/usr/lib/postgresql/12/bin/psql -p5433'

This works ask expected:

$ psql12 --set num=42 -ac "\echo :num"
echo :num
42

And so does this:

$ psql12 --set num=42
psql (12.11 (Ubuntu 12.11-1.pgdg18.04+1))
Type "help" for help.

postgres=# select :num;
 ?column?
----------
       42
(1 row)

But trying to use a variable (both with and without single quotes) in a
--command statement other than "\echo" throws a syntax error at the colon:

$ psql12 --set num=42 -ac "select :num;"
select :num;
ERROR:  syntax error at or near ":"
LINE 1: select :num;
               ^
$ psql12 --set num=42 -ac "select :'num';"
select :'num';
ERROR:  syntax error at or near ":"
LINE 1: select :'num';
               ^

What secret sauce am I missing to get this to work?

--
Angular momentum makes the world go 'round.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2022-07-28 19:47:11 Re: Syntax error when combining --set and --command has me stumped
Previous Message Peter J. Holzer 2022-07-28 18:03:09 Re: Was my question inappropriate for postgres?