From: | punch-hassle-guise(at)duck(dot)com |
---|---|
To: | pgsql-novice(at)lists(dot)postgresql(dot)org |
Subject: | Command Line option misunderstanding |
Date: | 2024-12-02 18:47:22 |
Message-ID: | 487DB217-EA37-4139-AB97-B61B04ECAEA7.1@smtp-inbound1.duck.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
It would appear that I have a fundamental misunderstanding
of either the english language or the psql man page.
A query of all the mailing lists returned no hits that I could find
relevant to this problem. Some references to platform dependent
ticks, hence my guessing on some attempts.
Perhaps some kind soul could enlighten me.
Thanks.
psql --version
psql (PostgreSQL) 15.10 (Debian 15.10-0+deb12u1)
Simple "HERE" document that works
psql -h anna -d GT7 << HERE
\set v1 12
select :v1;
HERE
autocommit on
?column?
----------
12
(1 row)
--end result--
Excerpt from man page
man psql
---cut----
-v assignment
--set=assignment
--variable=assignment
Perform a variable assignment, like the \set meta-command. Note
that you must separate name and value, if any, by an equal
sign on
the command line. To unset a variable, leave off the equal
sign. To
set a variable with an empty value, use the equal sign but leave
off the value. These assignments are done during command line
processing, so variables that reflect connection state will get
overwritten later.
---end cut ---
On the surface it would appear that -v implies declaration and
assignment of a single variable
to a value. -v VARIABLE_NAME=VARIABLE_VALUE
which of course doesn't work for me.
the -- options are even more problematic for me
These read to me as
--set=VARIABLE_NAME=VARIABLE_VALUE
and
--variable=VARIABLE_NAME=VARIABLE_VALUE
OR
--VARIABLE_NAME=VARIABLE_VALUE
and I could find no combination of any type of any of these that would
work for me.
My attempts at implementing my understanding of man page
and attempts at implementing what I perceive to be someones mis-writing
of man page
----attempt 1--
psql -h anna -d GT7 -v v1=12 -c 'select :v1'
autocommit on
ERROR: syntax error at or near ":"
LINE 1: select :v1
----end attempt---
---attempt 2 ---
psql -h anna -d GT7 -vv1=1 -c 'select ":v1" '
autocommit on
ERROR: column ":v1" does not exist
LINE 1: select ":v1"
---end attempt ---
--- atttempt 3----
psql -h anna -d GT7 -vv1=1 -c 'select :v1'
autocommit on
ERROR: syntax error at or near ":"
LINE 1: select :v1
---end attempt
---attempt 4----
sql -h anna -d GT7 -v "v1=1" -c "select :v1"
autocommit on
ERROR: syntax error at or near ":"
LINE 1: select ":v1"
--- end attempt---
---attempt 5 ---
psql -h anna -d GT7 -v 'v1=1' -c 'select ":v1" '
autocommit on
ERROR: column ":v1" does not exist
LINE 1: select ":v1"
----end attempt
--- attempt 6---
psql -h anna -d GT7 -v :v1=1 -c 'select ":v1" '
psql: error: invalid variable name: ":v1"
---end attempt
--- attempt 7 ---
psql -h anna -d GT7 -v "v1"=1 -c 'select ":v1" '
autocommit on
ERROR: column ":v1" does not exist
LINE 1: select ":v1"
--- end attempt
---attempt 8 ---
psql -h anna -d GT7 -v 'v1'=1 -c 'select ":v1" '
autocommit on
ERROR: column ":v1" does not exist
LINE 1: select ":v1"
--- end attempt ---
---attempt 9 ---
psql -h anna -d GT7 -c '\set v1 12; select ":v1" '
autocommit on
--- end attempt ----
--- attempt 10 ---
psql -h anna -d GT7 -c '\set v1=12; select ":v1" '
autocommit on
invalid variable name: "v1=12;"
---end attempt
---attempt 11 ---
psql -h anna -d GT7 -c '\set v1 = 12; select ":v1" '
autocommit on
---end attempt ---
---attempt 12 ---
psql -h anna -d GT7 -c '\set "v1 = 12"; select ":v1" '
autocommit on
invalid variable name: ""v1 = 12";"
---end attempt ----
---attempt 13 ----
psql -h anna -d GT7 -c '\set "v1=12"; select ":v1" '
autocommit on
invalid variable name: ""v1=12";"
---end attempt---
---attempt 14 ---
psql -h anna -d GT7 -c '\set "v1=12" select ":v1" '
autocommit on
invalid variable name: ""v1=12""
---end attempt---
---attempt 15---
psql -h anna -d GT7 -c '\set v1:=12; select ":v1" '
autocommit on
invalid variable name: "v1:=12;"
---end attempt---
---attempt 16 ---
kdibble(at)thinkstation:~/development/gt7-scraper$ psql -h anna -d GT7 -c
'\set v1:=12\n select ":v1" '
autocommit on
invalid variable name: "v1:=12"
---end attempt---
---attempt 17---
psql -h anna -d GT7 -c '\set v1 12\n select ":v1" '
autocommit on
---end attempt
---attempt 18---
psql -h anna -d GT7 -v --set v1=12 -c 'select :v1 '
Password for user v1=12:
---end attempt---
---attempt 19 ---
kdibble(at)thinkstation:~/development/gt7-scraper$ psql -h anna -d GT7
--set v1=12 -c 'select :v1 '
autocommit on
ERROR: syntax error at or near ":"
LINE 1: select :v1
---end attempt
--- attempt 20---
psql -h anna -d GT7 -v --set v1=12 -c 'select :v1 '
Password for user v1=12:
--end attempt---
---attempt 21 ---
psql -h anna -d GT7 -v v1 --set v1=12 -c 'select :v1 '
autocommit on
ERROR: syntax error at or near ":"
LINE 1: select :v1
---end attempt
---attempt 22 ---
psql -h anna -d GT7 -v v1 --set =12 -c 'select :v1 '
psql: error: invalid variable name: ""
---end attempt---
---attempt 23---
psql -h anna -d GT7 -v v1 --set 12 -c 'select :v1 '
autocommit on
ERROR: syntax error at or near ":"
LINE 1: select :v1
---end attempt
---attempt 24 ---
psql -h anna -d GT7 -v v1 --set v1=12 -c 'select :v1 '
autocommit on
ERROR: syntax error at or near ":"
LINE 1: select :v1
---end attempt---
---attempt 25---
psql -h anna -d GT7 -v --set v1=12 -c 'select :v1 '
Password for user v1=12:
----
---attempt 26 ---
psql -h anna -d GT7 --set v1=12 -c 'select :v1 '
autocommit on
ERROR: syntax error at or near ":"
LINE 1: select :v1
---end attempt
---attempt 27---
psql -h anna -d GT7 -v v1="3" -c "select :v1"
+ psql -h anna -d GT7 -v v1=3 -c 'select :v1'
autocommit on
ERROR: syntax error at or near ":"
LINE 1: select :v1
---end attempt
---attempt 28---
psql -h anna -d GT7 -v v1='3' -c "select :v1"
autocommit on
ERROR: syntax error at or near ":"
LINE 1: select :v1
--- end attempt ---
---attempt 29---
psql -h anna -d GT7 -c '\set v1 12; select :v1 '
autocommit on
---end attempt ---
---attempt 30 ---
psql -h anna -d GT7 -v --set v1:=12 -c 'select :v1 '
Password for user v1:=12:
---end attempt ---
---attempt 31 ---
psql -h anna -d GT7 --variable=v1=12 -c 'select :v1 '
autocommit on
ERROR: syntax error at or near ":"
LINE 1: select :v1
---end attempt---
---attempt 32---
psql -h anna -d GT7 --variable="v1=12" -c 'select :v1 '
autocommit on
ERROR: syntax error at or near ":"
LINE 1: select :v1
---end attempt---
From | Date | Subject | |
---|---|---|---|
Next Message | Joe Conway | 2024-12-02 20:12:34 | Re: Command Line option misunderstanding |
Previous Message | Joe Conway | 2024-11-19 19:42:05 | Re: Commitfest cooldown |