Re: psql -c command parse "select $$hello$$" failed - Mailing list pgsql-general

From Erik Wienhold
Subject Re: psql -c command parse "select $$hello$$" failed
Date
Msg-id 1823426797.696934.1688474716571@office.mailbox.org
Whole thread Raw
In response to psql -c command parse "select $$hello$$" failed  (jian he <jian.universality@gmail.com>)
List pgsql-general
> On 04/07/2023 14:21 CEST jian he <jian.universality@gmail.com> wrote:
>
> not sure this is the expected result.
>
> /home/jian/postgres/pg16_test/bin/psql -d test_dev -p 5455 -c "select $$hello$$"
> 2023-07-04 20:15:51.066 CST [1562050] ERROR:  trailing junk after
> numeric literal at or near "884070h" at character 8
> 2023-07-04 20:15:51.066 CST [1562050] STATEMENT:  select 884070hello884070
> ERROR:  trailing junk after numeric literal at or near "884070h"
> LINE 1: select 884070hello884070

The error is expected because the shell replaces $$ with its process ID inside
double quoted strings.  Check out Bash quoting [1] (assuming that you use bash
but this applies to every(?) shell).

Either use single quotes around the statement or escape every $ with \$:

    psql -c 'select $$hello$$'
    psql -c "select \$\$hello\$\$\"

[1] https://www.gnu.org/software/bash/manual/bash.html#Quoting

--
Erik



pgsql-general by date:

Previous
From: Julien Rouhaud
Date:
Subject: Re: psql -c command parse "select $$hello$$" failed
Next
From: Lorusso Domenico
Date:
Subject: Strange behaviour on function