On 12/2/24 15:13, Laurenz Albe wrote:
> On Mon, 2024-12-02 at 13:47 -0500, punch-hassle-guise@duck.com wrote:
>> psql -h anna -d GT7 -v v1=12 -c 'select :v1'
>>
>> autocommit on
>>
>> ERROR: syntax error at or near ":"
>> LINE 1: select :v1
> The documentation says:
>
> -c command
> --command=command
>
> [...]
>
> 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.
>
> Now variables are definitely a psql-specific feature, so variable substitution
> won't work. Use a here document!
>
> Yours,
> Laurenz Albe
As the beginning of this thread shows, I know how to do this with a HERE
document, I was just trying to clean it up.
I am not trying to be contentious, but a simple search shows that every
major implementation of SQL allows variables and there are hundreds if
not thousands of pages dedicated to the idea of using variables in SQL
and how they are fundamental.
There are certainly reasons this doesn't work, but saying variables are
psql specific......
Regards,
Ken