Search Postgresql Archives

Re: psql -c command parse "select $$hello$$" failed

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> On 04/07/2023 14:21 CEST jian he <jian.universality@xxxxxxxxx> 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





[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux