From: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> |
---|---|
To: | punch-hassle-guise(at)duck(dot)com |
Cc: | pgsql-novice(at)lists(dot)postgresql(dot)org |
Subject: | Re: Command Line option misunderstanding |
Date: | 2024-12-02 20:36:11 |
Message-ID: | CAKFQuwaNdRVNgKi014CGykDin43gsaSDgX+TKucbNsa-ZD1aEw@mail.gmail.com |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
On Mon, Dec 2, 2024 at 11:47 AM <punch-hassle-guise(at)duck(dot)com> wrote:
>
> ----attempt 1--
> psql -h anna -d GT7 -v v1=12 -c 'select :v1'
> ERROR: syntax error at or near ":"
> LINE 1: select :v1
>
> The variable got assigned correctly but it isn't in scope here due to the
how -c is implemented, as the others noted.
> ----end attempt---
>
> ---attempt 2 ---
> psql -h anna -d GT7 -vv1=1 -c 'select ":v1" '
> ERROR: column ":v1" does not exist
> LINE 1: select ":v1"
>
You double-quoted the whole thing so it's taken as a column name. Has no
relevance to the problem at hand.
> ---end attempt ---
>
> --- atttempt 3----
> psql -h anna -d GT7 -vv1=1 -c 'select :v1'
> ERROR: syntax error at or near ":"
> LINE 1: select :v1
>
Redundant with 1
> ---end attempt
>
> ---attempt 4----
> sql -h anna -d GT7 -v "v1=1" -c "select :v1"
> ERROR: syntax error at or near ":"
> LINE 1: select ":v1"
>
Redundant with 1 and 3, putting quotes around the shell option value only
makes explicit what is implicit/optional. This is also a shell usage
education issue, not psql specific.
> --- end attempt---
>
> ---attempt 5 ---
> psql -h anna -d GT7 -v 'v1=1' -c 'select ":v1" '
> ERROR: column ":v1" does not exist
> LINE 1: select ":v1"
>
Redundant with 2
> ----end attempt
>
> --- attempt 6---
> psql -h anna -d GT7 -v :v1=1 -c 'select ":v1" '
> psql: error: invalid variable name: ":v1"
>
Shell command failed since you cannot name a variable with a leading colon,
otherwise the chosen syntax for referencing a variable would be challenging
> ---end attempt
>
> --- attempt 7 ---
> psql -h anna -d GT7 -v "v1"=1 -c 'select ":v1" '
> ERROR: column ":v1" does not exist
> LINE 1: select ":v1"
>
Another redundant attempt using double-quotes
> --- end attempt
>
> ---attempt 8 ---
> psql -h anna -d GT7 -v 'v1'=1 -c 'select ":v1" '
> ERROR: column ":v1" does not exist
> LINE 1: select ":v1"
>
And again...
> --- end attempt ---
>
> ---attempt 9 ---
> psql -h anna -d GT7 -c '\set v1 12; select ":v1" '
>
... Not realizing how -c and meta-commands interplay (or don't in this
case) really led you to try lots of stuff that cannot work but is unrelated
to setting a variable.
> --- end attempt ----
>
Skipping 10-17 as redundant variations on not reading how -c works.
>
> ---attempt 18---
> psql -h anna -d GT7 -v --set v1=12 -c 'select :v1 '
> Password for user v1=12:
>
You can get odd errors when you don't following the syntax diagrams and
shell command writing rules...
> ---end attempt---
>
>
> ---attempt 19 ---
> kdibble(at)thinkstation:~/development/gt7-scraper$ psql -h anna -d GT7
> --set v1=12 -c 'select :v1 '
>
> ERROR: syntax error at or near ":"
> LINE 1: select :v1
>
Back to redundant with 1...
> ---end attempt
>
> --- attempt 20---
> psql -h anna -d GT7 -v --set v1=12 -c 'select :v1 '
> Password for user v1=12:
>
Again, not following syntax rules.
> --end attempt---
>
> ---attempt 21 ---
> psql -h anna -d GT7 -v v1 --set v1=12 -c 'select :v1 '
>
> ERROR: syntax error at or near ":"
> LINE 1: select :v1
>
And back to redundant with 1 after figuring out syntax rules for -v/--set
> ---end attempt
>
> ---attempt 22 ---
> psql -h anna -d GT7 -v v1 --set =12 -c 'select :v1 '
> psql: error: invalid variable name: ""
>
And now invalid shell syntax form for the set command.
> ---end attempt---
>
> ---attempt 23---
> psql -h anna -d GT7 -v v1 --set 12 -c 'select :v1 '
>
> ERROR: syntax error at or near ":"
> LINE 1: select :v1
>
> Redundant with 1 again...
> ---end attempt
>
> ---attempt 24 ---
> psql -h anna -d GT7 -v v1 --set v1=12 -c 'select :v1 '
>
> ERROR: syntax error at or near ":"
> LINE 1: select :v1
>
And again...
> ---end attempt---
>
> ---attempt 25---
> psql -h anna -d GT7 -v --set v1=12 -c 'select :v1 '
> Password for user v1=12:
>
Random stuff when inventing syntax again
> ----
>
> ---attempt 26 ---
> psql -h anna -d GT7 --set v1=12 -c 'select :v1 '
>
> ERROR: syntax error at or near ":"
> LINE 1: select :v1
>
Redundant with 1 again...
> ---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'
>
> ERROR: syntax error at or near ":"
> LINE 1: select :v1
>
Redundant with 1 again...
> ---end attempt
>
> ---attempt 28---
> psql -h anna -d GT7 -v v1='3' -c "select :v1"
> ERROR: syntax error at or near ":"
> LINE 1: select :v1
>
Redundant with again
> --- end attempt ---
>
> ---attempt 29---
> psql -h anna -d GT7 -c '\set v1 12; select :v1 '
>
Didn't read how -c works
> ---end attempt ---
>
> ---attempt 30 ---
> psql -h anna -d GT7 -v --set v1:=12 -c 'select :v1 '
> Password for user v1:=12:
>
Don't understand shell syntax for -v versus --set (repeat)
> ---end attempt ---
>
> ---attempt 31 ---
> psql -h anna -d GT7 --variable=v1=12 -c 'select :v1 '
> ERROR: syntax error at or near ":"
> LINE 1: select :v1
>
Redundant with 1 again
> ---end attempt---
>
> ---attempt 32---
> psql -h anna -d GT7 --variable="v1=12" -c 'select :v1 '
> ERROR: syntax error at or near ":"
> LINE 1: select :v1
>
Redundant with 1 again.
> ---end attempt---
>
If short, you figured out a bunch of ways to write valid and invalid
variable specifications. The invalid ones give you various different
errors. The correct ones all give you the same error since you cannot use
a variable along with -c, which is documented in -c, not variables, since
they get set just fine.
David J.
From | Date | Subject | |
---|---|---|---|
Next Message | punch-hassle-guise | 2024-12-02 21:21:18 | Re: Command Line option misunderstanding |
Previous Message | Laurenz Albe | 2024-12-02 20:13:28 | Re: Command Line option misunderstanding |