Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tIDA5-00Cvwa-JS for pgsql-novice@arkaria.postgresql.org; Mon, 02 Dec 2024 20:36:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tIDA3-003BXQ-2r for pgsql-novice@arkaria.postgresql.org; Mon, 02 Dec 2024 20:36:52 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tIDA2-003BXI-EM for pgsql-novice@lists.postgresql.org; Mon, 02 Dec 2024 20:36:52 +0000 Received: from mail-oa1-x29.google.com ([2001:4860:4864:20::29]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1tIDA0-000i44-Jd for pgsql-novice@lists.postgresql.org; Mon, 02 Dec 2024 20:36:50 +0000 Received: by mail-oa1-x29.google.com with SMTP id 586e51a60fabf-29737adb604so2551245fac.1 for ; Mon, 02 Dec 2024 12:36:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733171808; x=1733776608; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=xXTd7WMhU+Dd+mz3k0zsP8rwCwZejCja5Mlcany1bVU=; b=bivyf+BkR5516kCdhsXCTuPIEG4kW+b9W7FoUScpfN3xPRJGIfKhjMMM/99asCIcZ9 4S4Ce3YpqiBtyU2dCj2/3jxRpvxCKnYCNjLpJKDUWBKES3iChX16YAmJR8qz/lZEcbVS Iq2DDXAfzeAB7fDwjEcL0lPkD/cswxWwNKdi0A7SFaX31CmyRKBRwG0cIYUMr4lfJT6h 3XcjgRtyePBOWXXvptgKMWt1glSWxhsYjXhfB33Hww8snrJcMYH776m0xzsjWVoCm5Y2 Sat9wipfvrtMCbPZQYNffd7eKEQvR1ztAN/1DtU2/hPCq4x3CHWb8J1VRoIn95vntp6Q 90iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733171808; x=1733776608; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xXTd7WMhU+Dd+mz3k0zsP8rwCwZejCja5Mlcany1bVU=; b=p8pi0Y3IwJoo9BriY4KQJu8jhBa5WQ+dxOi5CA49n9J8naYpkQqK9hfJn/pZLq69+9 fbyk/cA+5qWa14pcfIaAd/Oaj6nkXuAkxsA7bg0Kl1VezpKopHispZlzNeYSBaqx+cku d3f3ZY4yyjvIw3OvQ8tdf5UkEc/XsGZl+SMyaPENp7q/vAAnGXYxZKXV2BBEkWXq9G2X 9PDBJq/HQpXBRXM/d99PfK7W3Hti0omWI6N6STei9l3yNunydm71Du+7lrFBOpP6AnUl q86g5F8tWK1ICOrYFZuMLztr3OvtVE95d9cwlu/ES3CFXM018VD9j1wpYRJ75orPj1ND z8TA== X-Gm-Message-State: AOJu0YyLR46tgtbxcFwBD8EahpRgG/7lcKB4gi/6YPQxvJX4wGsz/t8u MjzKFkFpbvJYxYbl8YKHZvGIKXxO1G6NNltMjwoPpPF5nAb10s+MsGNB0qbDDRO0XdD6BO08t6k y2ToOpuijpNb3tZRDputZtsKbFrTclkKE X-Gm-Gg: ASbGncuPLhwlexiFybHi6w/W4wlQRGNSZteFRCi++jHMgmS6u5q/MwoEy5oqv6+V25P lcnRIRxPg4NYc1JpugUGI8QA+ULTY29o= X-Google-Smtp-Source: AGHT+IGR9iEqOeOtHagW0qXb1dQaDIdLYJENcdPqFH1Ry/oHiOdYFAYuzgHghyT7UhChDpJBVAzludYx2J787/s+a5o= X-Received: by 2002:a05:6870:829f:b0:29e:67cd:1a89 with SMTP id 586e51a60fabf-29e67cd1e39mr4873216fac.36.1733171807752; Mon, 02 Dec 2024 12:36:47 -0800 (PST) MIME-Version: 1.0 References: <487DB217-EA37-4139-AB97-B61B04ECAEA7.1@smtp-inbound1.duck.com> In-Reply-To: <487DB217-EA37-4139-AB97-B61B04ECAEA7.1@smtp-inbound1.duck.com> From: "David G. Johnston" Date: Mon, 2 Dec 2024 13:36:11 -0700 Message-ID: Subject: Re: Command Line option misunderstanding To: punch-hassle-guise@duck.com Cc: pgsql-novice@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000ef96e706284f81fe" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000ef96e706284f81fe Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Dec 2, 2024 at 11:47=E2=80=AFAM wrote= : > > ----attempt 1-- > psql -h anna -d GT7 -v v1=3D12 -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=3D1 -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=3D1 -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=3D1" -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=3D1' -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=3D1 -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"=3D1 -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'=3D1 -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=3D12 -c 'select :v1 ' > Password for user v1=3D12: > You can get odd errors when you don't following the syntax diagrams and shell command writing rules... > ---end attempt--- > > > ---attempt 19 --- > kdibble@thinkstation:~/development/gt7-scraper$ psql -h anna -d GT7 > --set v1=3D12 -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=3D12 -c 'select :v1 ' > Password for user v1=3D12: > Again, not following syntax rules. > --end attempt--- > > ---attempt 21 --- > psql -h anna -d GT7 -v v1 --set v1=3D12 -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 =3D12 -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=3D12 -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=3D12 -c 'select :v1 ' > Password for user v1=3D12: > Random stuff when inventing syntax again > ---- > > ---attempt 26 --- > psql -h anna -d GT7 --set v1=3D12 -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=3D"3" -c "select :v1" > + psql -h anna -d GT7 -v v1=3D3 -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=3D'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:=3D12 -c 'select :v1 ' > Password for user v1:=3D12: > Don't understand shell syntax for -v versus --set (repeat) > ---end attempt --- > > ---attempt 31 --- > psql -h anna -d GT7 --variable=3Dv1=3D12 -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=3D"v1=3D12" -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. --000000000000ef96e706284f81fe Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, Dec 2, 2024 at 11:47=E2=80=AFAM <punch-hassle-guise@duck.com> wrote:=

----attempt 1--
psql -h anna -d GT7 -v v1=3D12 -c 'select :v1'
ERROR:=C2=A0 synt= ax error at or near ":"
LINE 1: select :v1

The variable got assigned correctly but it isn= 9;t in scope here due to the how -c is implemented, as the others noted.
=C2=A0
You double-quoted t= he whole thing so it's taken as a column name.=C2=A0 Has no relevance t= o the problem at hand.=C2=A0
---end attempt ---

--- atttempt 3----
psql -h anna -d GT7 -vv1=3D1 -c 'select :v1'
ERROR:=C2=A0 syntax= error at or near ":"
LINE 1: select :v1
Redundant with 1=C2=A0
---end attempt

---attempt 4----
sql -h anna -d GT7 -v "v1=3D1"=C2=A0 -c "select :v1"ERROR:=C2=A0 syntax error at or near ":"
LINE 1: select ":v1"
Redundant with 1 an= d 3, putting quotes around the shell option value only makes explicit what = is implicit/optional.=C2=A0 This is also a shell usage education issue, not= psql specific.=C2=A0
--- end attempt---

---attempt 5 ---
psql -h anna -d GT7 -v 'v1=3D1'=C2=A0 -c 'select ":v1"= ; '
ERROR:=C2=A0 column ":v1" does not exist
LINE 1: select ":v1"
Redundant with 2=C2=A0
----end attempt

--- attempt 6---
psql -h anna -d GT7 -v :v1=3D1=C2=A0 -c 'select ":v1" ' psql: error: invalid variable name: ":v1"
Shell command failed since you cannot name a variable with a leading colo= n, otherwise the chosen syntax for referencing a variable would be challeng= ing=C2=A0
---end attempt

--- attempt 7 ---
psql -h anna -d GT7 -v "v1"=3D1=C2=A0 -c 'select ":v1&qu= ot; '
ERROR:=C2=A0 column ":v1" does not exist
LINE 1: select ":v1"
Another redundant a= ttempt using double-quotes=C2=A0
--- end attempt

---attempt 8 ---
psql -h anna -d GT7 -v 'v1'=3D1=C2=A0 -c 'select ":v1"= ; '
ERROR:=C2=A0 column ":v1" does not exist
LINE 1: select ":v1"
And again...= =C2=A0
--- end attempt ---

---attempt 9 ---
=C2=A0=C2=A0psql -h anna -d GT7=C2=A0=C2=A0 -c '\set v1 12; select &quo= t;:v1" '
... Not realizing how -c and meta-commands interplay (or don= 9;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 work= s.



---attempt 18---
psql -h anna -d GT7=C2=A0 -v=C2=A0 --set v1=3D12 -c 'select :v1 ' Password for user v1=3D12:
You can get odd errors = when you don't following the syntax diagrams and shell command writing = rules...=C2=A0
Back to redundant with 1...=C2=A0
---end attempt

--- attempt 20---
psql -h anna -d GT7=C2=A0=C2=A0 -v --set v1=3D12 -c 'select :v1 ' Password for user v1=3D12:
Again, not following sy= ntax rules.=C2=A0
--end attempt---

---attempt 21 ---
=C2=A0=C2=A0psql -h anna -d GT7=C2=A0=C2=A0 -v v1=C2=A0 --set v1=3D12 -c &#= 39;select :v1 '

ERROR:=C2=A0 syntax error at or near ":"
LINE 1: select :v1
And back to redundant with 1 af= ter figuring out syntax rules for -v/--set=C2=A0
---end attempt

---attempt 22 ---
psql -h anna -d GT7=C2=A0=C2=A0 -v v1=C2=A0 --set =3D12 -c 'select :v1 = '
psql: error: invalid variable name: ""
A= nd now invalid shell syntax form for the set command.=C2=A0
---end attempt---

---attempt 23---
psql -h anna -d GT7=C2=A0=C2=A0 -v v1 --set 12 -c 'select :v1 '

ERROR:=C2=A0 syntax error at or near ":"
LINE 1: select :v1

Redundant with 1 again...=C2=A0
---end attempt

---attempt 24 ---
psql -h anna -d GT7=C2=A0=C2=A0 -v v1=C2=A0 --set v1=3D12 -c 'select :v= 1 '

ERROR:=C2=A0 syntax error at or near ":"
LINE 1: select :v1
And again...=C2=A0
=
---end attempt---

---attempt 25---
psql -h anna -d GT7=C2=A0=C2=A0=C2=A0 -v --set v1=3D12 -c 'select :v1 &= #39;
Password for user v1=3D12:
Random stuff when inven= ting syntax again=C2=A0
----

---attempt 26 ---
psql -h anna -d GT7=C2=A0=C2=A0=C2=A0 --set v1=3D12 -c 'select :v1 '= ;

ERROR:=C2=A0 syntax error at or near ":"
LINE 1: select :v1
Redundant with 1 again...=C2=A0
---end attempt

---attempt 27---
=C2=A0=C2=A0psql -h anna -d GT7=C2=A0 -v v1=3D"3" -c "select= :v1"
+ psql -h anna -d GT7 -v v1=3D3 -c 'select :v1'

ERROR:=C2=A0 syntax error at or near ":"
LINE 1: select :v1
Redundant with 1 again...=C2=A0
---end attempt

---attempt 28---
psql -h anna -d GT7=C2=A0 -v v1=3D'3' -c "select :v1"
= ERROR:=C2=A0 syntax error at or near ":"
LINE 1: select :v1
Redundant with again=C2= =A0
--- end attempt ---

---attempt 29---
psql -h anna -d GT7=C2=A0=C2=A0 -c '\set v1 12; select :v1 '
Didn't read how -c works=C2=A0
---end attempt ---

---attempt 30 ---
psql -h anna -d GT7 -v --set v1:=3D12 -c 'select :v1 '
Password for user v1:=3D12:
Don't understand s= hell syntax for -v versus --set (repeat)=C2=A0
---end attempt ---

---attempt 31 ---
psql -h anna -d GT7=C2=A0 --variable=3Dv1=3D12 -c 'select :v1 '
= ERROR:=C2=A0 syntax error at or near ":"
LINE 1: select :v1
Redundant with 1 again= =C2=A0
---end attempt---

---attempt 32---
psql -h anna -d GT7=C2=A0 --variable=3D"v1=3D12" -c 'select := v1 '
ERROR:=C2=A0 syntax error at or near ":"
LINE 1: select :v1
Redundant with 1 again.= =C2=A0
---end attempt---

If short, you figured o= ut a bunch of ways to write valid and invalid variable specifications. The = invalid ones give you various different errors.=C2=A0 The correct ones all = give you the same error since you cannot use a variable along with -c, whic= h is documented in -c, not variables, since they get set just fine.
=C2=A0
David J.
=C2=A0
--000000000000ef96e706284f81fe--