pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #17736: when psql -c is used, the $ sign is escaped
2+ messages / 2 participants
[nested] [flat]

* BUG #17736: when psql -c is used, the $ sign is escaped
@ 2023-01-04 02:48  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2023-01-04 02:48 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: dafoer_x@163.com

The following bug has been logged on the website:

Bug reference:      17736
Logged by:          dafoer_x
Email address:      dafoer_x@163.com
PostgreSQL version: 14.0
Operating system:   centos
Description:        

[pg14@VM-219-249-centos ~]$ psql -d postgres -p 29822 -h 127.0.0.1 -c "set
lc_monetary='en_US.UTF-8'; drop table if exists t_mony; create table
t_mony(c1 bigint,c2 money); insert into t_mony values(2,'$1.00'); select *
from t_mony;"
 c1 |  c2   
----+-------
  2 | $0.00
(1 row)

postgres=# set lc_monetary='en_US.UTF-8'; drop table if exists t_mony;
create table t_mony(c1 bigint,c2 money); insert into t_mony
values(2,'$1.00'); select * from t_mony;
SET
DROP TABLE
CREATE TABLE
INSERT 0 1
 c1 |  c2   
----+-------
  2 | $1.00
(1 row)

Because $ is escaped, the results are different when the same command is
executed in psql and internally.
I would like to ask how to solve this problem, or why there is this
difference?

Regards



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #17736: when psql -c is used, the $ sign is escaped
@ 2023-01-04 13:34  John Naylor <john.naylor@enterprisedb.com>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: John Naylor @ 2023-01-04 13:34 UTC (permalink / raw)
  To: dafoer_x@163.com; pgsql-bugs@lists.postgresql.org

On Wed, Jan 4, 2023 at 5:00 PM PG Bug reporting form <noreply@postgresql.org>
wrote:
> Because $ is escaped, the results are different when the same command is
> executed in psql and internally.
> I would like to ask how to solve this problem, or why there is this
> difference?

When passing a quoted argument to psql, it is necessary to account for the
shell's interpretation, for example:

$ echo "foo $1"
foo

$ echo "foo \$1"
foo $1

--
John Naylor
EDB: http://www.enterprisedb.com

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2023-01-04 13:34 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-01-04 02:48 BUG #17736: when psql -c is used, the $ sign is escaped PG Bug reporting form <noreply@postgresql.org>
2023-01-04 13:34 ` John Naylor <john.naylor@enterprisedb.com>

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