Re: psql --command option ignores --variable's

From: Tim Kane <tim(dot)kane(at)gmail(dot)com>
To: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
Cc: pgsql-general General <pgsql-general(at)postgresql(dot)org>
Subject: Re: psql --command option ignores --variable's
Date: 2013-09-02 15:53:12
Message-ID: CE4A72AF.1E301%tim.kane@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


Ahh, ok. It is documented. I'll get back in my box :)

On 02/09/2013 16:04, "Adrian Klaver" <adrian(dot)klaver(at)gmail(dot)com> wrote:

>On 09/02/2013 07:54 AM, Tim Kane wrote:
>> Hi all,
>>
>> It seems the behaviour of the ‹command / -c option is such that it will
>> ignore any variables set on the command-line.
>>
>>
>> :~ psql --variable TESTVAR='123' --command 'select :TESTVAR;'
>> ERROR: syntax error at or near ":"
>> LINE 1: select :TESTVAR;
>> ^
>>
>> :~$ psql --variable TESTVAR='123'
>> psql (9.1.9)
>> Type "help" for help.
>>
>> timk=> select :TESTVAR;
>> ?column?
>> ----------
>> 123
>> (1 row)
>>
>>
>>
>> Obviously, there are ways around this, but is this expected behaviour?
>
>See *--> section below.
>http://www.postgresql.org/docs/9.1/interactive/app-psql.html
>
>-c command
>--command=command
>Specifies that psql is to execute one command string, command, and then
>exit. This is useful in shell scripts. Start-up files (psqlrc and
>~/.psqlrc) are ignored with this option.
>
>*-->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. Thus you cannot mix SQL and psql meta-commands with
>this option. To achieve that, you could pipe the string into psql, like
>this: echo '\x \\ SELECT * FROM foo;' | psql. (\\ is the separator
>meta-command.)
><--*
>
>If the command string contains multiple SQL commands, they are processed
>in a single transaction, unless there are explicit BEGIN/COMMIT commands
>included in the string to divide it into multiple transactions. This is
>different from the behavior when the same string is fed to psql's
>standard input. Also, only the result of the last SQL command is returned.
>
>
>
>>
>>
>> Tim
>
>
>--
>Adrian Klaver
>adrian(dot)klaver(at)gmail(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jeff Janes 2013-09-02 19:06:58 Re: My Experiment of PG crash when dealing with huge amount of data
Previous Message David Johnston 2013-09-02 15:41:51 Re: STABLE marker on functions with single select