Escaping single quotes with backslash seems not to work

From: Ron Johnson <ronljohnsonjr(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Escaping single quotes with backslash seems not to work
Date: 2024-06-10 14:02:14
Message-ID: CANzqJaD0=V+Dh+mLLfLj4ECLHriAH122LiYaqKyAnWCAKCfa6A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G. Johnston 2024-06-10 14:07:44 Re: Escaping single quotes with backslash seems not to work
Previous Message Torsten Förtsch 2024-06-10 12:06:58 Vacuum backend with backend_xmin?