Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGfbV-00FkGq-JN for pgsql-general@arkaria.postgresql.org; Mon, 10 Jun 2024 14:02:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sGfbU-00CRkK-3Y for pgsql-general@arkaria.postgresql.org; Mon, 10 Jun 2024 14:02:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sGfbT-00CRiO-Ow for pgsql-general@lists.postgresql.org; Mon, 10 Jun 2024 14:02:32 +0000 Received: from mail-oa1-x2e.google.com ([2001:4860:4864:20::2e]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sGfbR-000wZH-Sl for pgsql-general@postgresql.org; Mon, 10 Jun 2024 14:02:32 +0000 Received: by mail-oa1-x2e.google.com with SMTP id 586e51a60fabf-24c9f630e51so2228185fac.1 for ; Mon, 10 Jun 2024 07:02:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718028147; x=1718632947; darn=postgresql.org; h=to:subject:message-id:date:from:mime-version:from:to:cc:subject :date:message-id:reply-to; bh=CwTTRY/5lQh/UBE1hRivlV7or7Gu1lbVVVdd9u87yQg=; b=g456xufEiC5U6lP5VWTKISR5GnaSQQKvrFNHpDBVwO1HK+UQw3uWVCMDQLP2obvVT7 VuT7ZLIP1ROfuI2gtwKa4k2JrMhVvU4AlW7mZhHXE/Zjty11iTcjUsrRy6GU1huiFMai bG7Ev2mh6sG3zps/VstU6ZCuKhn7FPadldetE8Buzc4K280+NOqiVHA5bdyqN9UZG/vs OhuJ6js4wK/iAWLFEHhXgL2EggfqalBbBd4wqfoLBpfieuuYnjqocA8xfoKcW6smJooF hsyAhHg/udrDIuNBQ83iNKpyPW51Tgt5phIpUZLVrelvl6/XQ8rXSeJ3Fhue7iscq5xK wjMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718028147; x=1718632947; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=CwTTRY/5lQh/UBE1hRivlV7or7Gu1lbVVVdd9u87yQg=; b=Wala2XTyw+vucNiWxu1DER0hHJ/zrMmOIka3hBCaxT8JbIH2GPyGXxgPSLytQZYRUY K7NKyp2OVIFxWL+R2yjwwtsXpYRfpSPwFytIGnaPDbEEYIA9XhF2Mgcg+GNZ1Dwou1FN F1FUihft7htx8Qkv6bE0gPcFBpGXZxV0s+lkm/sBn19Bh2aKOVE+iXvIn4AYCQDqZvF/ g8nNDe1budl+Pp/7eam21lFARjTB8h62WzuVbe9PY7TCTwyPYRR7hCoODTM+Xak4vG3K A1tQz/OVLJ79s3cSt0clHlAbwbV6ckCncuNRZ85ZDFBmpudToEAcLDBGiPWfKP5UWLOs zFlQ== X-Gm-Message-State: AOJu0YzGftZShBQs9af3Jp4x9S72eSfAnO3deO76yOV5Z+lG3ZUCvKL3 lQLdvZogFGm0XnctjEiaYTRaYN9MRfrqaJ8r/jUoWRTD8J3D7E1EGGik9vNMVmAYIGYv+8QdZD/ sX2f5QHmstxrTfVelrd/6OXY+9jag0uvZ X-Google-Smtp-Source: AGHT+IHKKhzBXjxgvQ5boEvxGPWRMno2nYN+x4MNWqBzGBpXJ4LR4BfrNP2ji+KbxK6w0wRu70+U88U3VJ372UQy74o= X-Received: by 2002:a05:6870:970b:b0:24f:e8f1:675b with SMTP id 586e51a60fabf-2546460c605mr9965597fac.30.1718028146791; Mon, 10 Jun 2024 07:02:26 -0700 (PDT) MIME-Version: 1.0 From: Ron Johnson Date: Mon, 10 Jun 2024 10:02:14 -0400 Message-ID: Subject: Escaping single quotes with backslash seems not to work To: pgsql-general Content-Type: multipart/alternative; boundary="000000000000675ae6061a8999b9" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000675ae6061a8999b9 Content-Type: text/plain; charset="UTF-8" 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) --000000000000675ae6061a8999b9 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
PG 9.6 and PG 14

[quote]
Any other character following a backslash is taken l= iterally. Thus, to include a backslash character, write two backslashes (\\). Also, a single quote= can be included in an escape string by writing=C2=A0\', in addition to the normal way of=C2= =A0''.
[/quote]

But it doesn't seem to wo= rk.=C2=A0 Obviously there's some misconfiguration or , but I don't = see what I did wrong.

TAP=3D# insert into foo (name, description) = values ('XYZ_Name ', '''XYZ ''');
INSERT= 0 1

TAP=3D# insert into foo (name, description) values ('XYZ_Na= me ', '\'XYZ ');
TAP'#
TAP'# ');
ERRO= R: =C2=A0syntax error at or near "XYZ"
LINE 1: ...into foo (na= me, description) values ('XYZ_Name ', '\'XYZ ');

TAP=3D# show standard_conforming_strings;
=C2=A0standard_con= forming_strings
-----------------------------
=C2=A0on
(1 row)
TAP=3D#
TAP=3D# show backslash_quote;
=C2=A0backslash_quote -----------------
=C2=A0safe_encoding
(1 row)
<= br>

--000000000000675ae6061a8999b9--