pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Erik Wienhold <ewie@ewie.name>
To: jian he <jian.universality@gmail.com>
To: pgsql-general list <pgsql-general@lists.postgresql.org>
Subject: Re: psql -c command parse "select $$hello$$" failed
Date: Tue, 4 Jul 2023 14:45:16 +0200 (CEST)
Message-ID: <1823426797.696934.1688474716571@office.mailbox.org> (raw)
In-Reply-To: <CACJufxG=gshS2XPrTBAJNOfw7n=0OpnUtf6L0Q5shzMc8oQxqQ@mail.gmail.com>
References: <CACJufxG=gshS2XPrTBAJNOfw7n=0OpnUtf6L0Q5shzMc8oQxqQ@mail.gmail.com>

> 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





view thread (3+ messages)

Message-ID: <1823426797.696934.1688474716571@office.mailbox.org>
Permalink:  ../1823426797.696934.1688474716571@office.mailbox.org/
Also on:    postgresql.org/message-id/1823426797.696934.1688474716571@office.mailbox.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: ewie@ewie.name, jian.universality@gmail.com
  Subject: Re: psql -c command parse "select $$hello$$" failed
  In-Reply-To: <1823426797.696934.1688474716571@office.mailbox.org>
  References: <CACJufxG=gshS2XPrTBAJNOfw7n=0OpnUtf6L0Q5shzMc8oQxqQ@mail.gmail.com> <1823426797.696934.1688474716571@office.mailbox.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox