Re: psql scripting tutorials - Mailing list pgsql-general

From Peter Eisentraut
Subject Re: psql scripting tutorials
Date
Msg-id 48C93B07.8080100@gmx.net
Whole thread Raw
In response to Re: psql scripting tutorials  (Harald Fuchs <hari.fuchs@gmail.com>)
Responses Re: psql scripting tutorials  (Alvaro Herrera <alvherre@commandprompt.com>)
List pgsql-general
Harald Fuchs wrote:
> In article <Pine.GSO.4.64.0809110111250.244@westnet.com>,
> Greg Smith <gsmith@gregsmith.com> writes:
>
>> On Tue, 9 Sep 2008, Artacus wrote:
>>> Can psql access environmental variables or command line params?
>
>> $ cat test.sql
>> select :TEST as "input";
>> $ psql -v TEST=16 -f test.sql
>>  input
>> -------
>>     16
>> (1 row)
>
> Nice trick, but when I try the following variant:
>
>   psql -v TEST=16 -c 'select :TEST as "input"'
>
> I get
>
>   ERROR:  syntax error at or near ":"
>   LINE 1: select :TEST as "input"
>
> This seems to be contrary to the psql manual page:
>
>  These assignments are done during a very early stage of start-up...
>
>

psql manual page:

    -c command

    --command command
           Specifies that psql is to execute one command string, command,
           and then exit. This is useful in shell scripts.

           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.


pgsql-general by date:

Previous
From: Peter Eisentraut
Date:
Subject: Re: No error when column doesn't exist
Next
From: "Scott Marlowe"
Date:
Subject: Re: declare column update expression