public inbox for [email protected]  
help / color / mirror / Atom feed
From: David G. Johnston <[email protected]>
To: [email protected]
Cc: Laurenz Albe <[email protected]>
Cc: [email protected] <[email protected]>
Subject: Re: Command Line option misunderstanding
Date: Mon, 2 Dec 2024 17:11:13 -0700
Message-ID: <CAKFQuwa2PnJkTm=OyZznsoSEVw+4UyzX+7j43+Y=+=bZWWqNBA@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>
	<[email protected]>

On Mon, Dec 2, 2024 at 4:50 PM <[email protected]> wrote:

> The problem seems to be, as alluded to by others attempting to help me
>
> that the problem only exists when using -c on the same line as -v.
>
The word "line" here belies further misunderstanding of how shell-executed
commands work (the following "two line" command is still just one actual
multiple-option command invocation).
psql -v a=1 \
-c 'select :a'

It is best to just say "using -c and -v together".

It is correct that we haven't pointed out, probably because for experienced
people it seems obvious, that using -v and -c (or putting \set in -c) is a
pointless thing to do.  But psql doesn't go about trying to analyze intent
here so, yes, you either get useless successful output in response or a
confused server.

That said...
psql -v a=1 -c '\echo :a' postgres
1

So it truly is just this specific SQL-related usage that is pointless, not
combining -v and -c generally (I'm sure a useful backslash command can be
substituted for \echo)

>
> Related Question:
>
> Documentation says:
>
> *command* must be either a command string that is completely parsable by
> the server (i.e., it contains no psql-specific features), or a single
> backslash command.
>
> $psql -h anna -d GT7   -c "\set  a '11117' \\ select evt_id from events
> where sport_mode_evt_id=:a"
>
Really not caring that you are turning on autocommit...

Anyway, what I believe you managed to accomplish here is to set the named
variable "a" to the value <single-quote 11117 single-quote blah-blah-blah
equals colon a>

Then proceeded to do nothing with that variable since the -c command was
done being evaluated in the "single backslash command" mode.

David J.


reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Command Line option misunderstanding
  In-Reply-To: <CAKFQuwa2PnJkTm=OyZznsoSEVw+4UyzX+7j43+Y=+=bZWWqNBA@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox