public inbox for [email protected]
help / color / mirror / Atom feedEscaping single quotes with backslash seems not to work
2+ messages / 2 participants
[nested] [flat]
* Escaping single quotes with backslash seems not to work
@ 2024-06-10 14:02 Ron Johnson <[email protected]>
2024-06-10 14:07 ` Re: Escaping single quotes with backslash seems not to work David G. Johnston <[email protected]>
0 siblings, 1 reply; 2+ messages in thread
From: Ron Johnson @ 2024-06-10 14:02 UTC (permalink / raw)
To: pgsql-general
PG 9.6 and PG 14
https://www.postgresql.org/docs/14/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS
[quote]
Any other character following a backslash is taken literally. Thus, to
include a backslash character, write two backslashes (\\). Also, a single
quote can be included in an escape string by writing \', in addition to the
normal way of ''.
[/quote]
But it doesn't seem to work. Obviously there's some misconfiguration or ,
but I don't see what I did wrong.
TAP=# insert into foo (name, description) values ('XYZ_Name ', '''XYZ ''');
INSERT 0 1
TAP=# insert into foo (name, description) values ('XYZ_Name ', '\'XYZ ');
TAP'#
TAP'# ');
ERROR: syntax error at or near "XYZ"
LINE 1: ...into foo (name, description) values ('XYZ_Name ', '\'XYZ ');
TAP=# show standard_conforming_strings;
standard_conforming_strings
-----------------------------
on
(1 row)
TAP=#
TAP=# show backslash_quote;
backslash_quote
-----------------
safe_encoding
(1 row)
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Escaping single quotes with backslash seems not to work
2024-06-10 14:02 Escaping single quotes with backslash seems not to work Ron Johnson <[email protected]>
@ 2024-06-10 14:07 ` David G. Johnston <[email protected]>
0 siblings, 0 replies; 2+ messages in thread
From: David G. Johnston @ 2024-06-10 14:07 UTC (permalink / raw)
To: Ron Johnson <[email protected]>; +Cc: pgsql-general
On Mon, Jun 10, 2024 at 7:02 AM Ron Johnson <[email protected]> wrote:
> PG 9.6 and PG 14
>
>
> https://www.postgresql.org/docs/14/sql-syntax-lexical.html#SQL-SYNTAX-CONSTANTS
>
> [quote]
> Any other character following a backslash is taken literally. Thus, to
> include a backslash character, write two backslashes (\\). Also, a single
> quote can be included in an escape string by writing \', in addition to
> the normal way of ''.
> [/quote]
>
>
The link you provided goes to the wrong subsection. The following
subsection, which discusses, String Constants With C-Style Escapes,
requires that you write the literal as E'abc\'def'
Note the E prefix on the literal, which is the thing that enables
considering backslash as an escape.
David J.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2024-06-10 14:07 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2024-06-10 14:02 Escaping single quotes with backslash seems not to work Ron Johnson <[email protected]>
2024-06-10 14:07 ` David G. Johnston <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox