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.98.2) (envelope-from ) id 1x7TxP-00000000PPi-15KJ for pgsql-bugs@arkaria.postgresql.org; Fri, 18 Sep 2026 08:28:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x7TxO-00000008px0-1Ry3 for pgsql-bugs@arkaria.postgresql.org; Fri, 18 Sep 2026 08:28:30 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x7T4p-00000008NNB-2cka for pgsql-bugs@lists.postgresql.org; Fri, 18 Sep 2026 07:32:07 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1x7T4o-00000000Hrp-0Gfl for pgsql-bugs@lists.postgresql.org; Fri, 18 Sep 2026 07:32:06 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=vQfMNXiuvix/Wwg1+VgLnD0nwXkIR3tdgot4eAelUgA=; b=IBqD8Dnw9MgmoBr5IlpxzEKcX+ 213+L0HHDcelAUCrI4+zrj58WmSnbUP3d49eCjjS+0GrA694Lg+vNhp8UuV6ygj+h8wu8K7J7pcld Gk14ju+epFBSQyQpsyUwvBhkWsj1T8cLvMyXkGeTjkQ1QILciWbY9BsS51pYgwJQYPsVM6VX6XEBz afvJoy43Gc5NeMBlgjBt58URCJJe0r68EqqCxuG59uIQUBXgoTSxnYVBoj+pvJTvnKl25YR8Hv3Uv MM/D16rXgzdhH976HdCTkcYoRLQYTisiizGW215MFR7Kh4bhpSBXZqn1VrGJc3BDE8VnQ0e0ZJU0j KgRig4/A==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x7T4m-001vgw-2c for pgsql-bugs@lists.postgresql.org; Fri, 18 Sep 2026 07:32:05 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1x7T4l-000000078dk-1xsz for pgsql-bugs@lists.postgresql.org; Fri, 18 Sep 2026 07:32:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19699: LIKE with a trailing escape fails to raise SQLSTATE 22025 for empty input To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: imchifan@163.com Reply-To: imchifan@163.com, pgsql-bugs@lists.postgresql.org Date: Fri, 18 Sep 2026 07:31:04 +0000 Message-ID: <19699-dbaa58bbf8db1859@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The following bug has been logged on the website: Bug reference: 19699 Logged by: Qifan Liu Email address: imchifan@163.com PostgreSQL version: 18.6 Operating system: Linux/amd64 Description: =20 PostgreSQL version: PostgreSQL 20devel at a12600b762c36d91450ce085fa25ef75250bc1c2; PostgreSQL 18.6; PostgreSQL 17.11 Operating system: Linux/amd64 Description ----------- LIKE does not reject a pattern ending in its active escape character when the input string is empty. Both the default backslash escape and a custom escape silently return instead of raising SQLSTATE 22025. The equivalent cases with nonempty input raise 22025. Steps to reproduce ------------------ Run the following input with psql: BEGIN; CREATE TEMP TABLE bugseer_postgres_00013_like_escape_results ( case_name text PRIMARY KEY, returned_sqlstate text ); DO $block$ DECLARE state text; BEGIN PERFORM ''::text LIKE E'\\'; INSERT INTO bugseer_postgres_00013_like_escape_results VALUES ('empty_default', NULL); EXCEPTION WHEN OTHERS THEN GET STACKED DIAGNOSTICS state =3D RETURNED_SQLSTATE; INSERT INTO bugseer_postgres_00013_like_escape_results VALUES ('empty_default', state); END $block$; DO $block$ DECLARE state text; BEGIN PERFORM 'x'::text LIKE E'\\'; INSERT INTO bugseer_postgres_00013_like_escape_results VALUES ('nonempty_default', NULL); EXCEPTION WHEN OTHERS THEN GET STACKED DIAGNOSTICS state =3D RETURNED_SQLSTATE; INSERT INTO bugseer_postgres_00013_like_escape_results VALUES ('nonempty_default', state); END $block$; DO $block$ DECLARE state text; BEGIN PERFORM ''::text LIKE '#' ESCAPE '#'; INSERT INTO bugseer_postgres_00013_like_escape_results VALUES ('empty_custom', NULL); EXCEPTION WHEN OTHERS THEN GET STACKED DIAGNOSTICS state =3D RETURNED_SQLSTATE; INSERT INTO bugseer_postgres_00013_like_escape_results VALUES ('empty_custom', state); END $block$; DO $block$ DECLARE state text; BEGIN PERFORM 'x'::text LIKE '#' ESCAPE '#'; INSERT INTO bugseer_postgres_00013_like_escape_results VALUES ('nonempty_custom', NULL); EXCEPTION WHEN OTHERS THEN GET STACKED DIAGNOSTICS state =3D RETURNED_SQLSTATE; INSERT INTO bugseer_postgres_00013_like_escape_results VALUES ('nonempty_custom', state); END $block$; TABLE bugseer_postgres_00013_like_escape_results; SELECT count(*) =3D 4 AS all_cases_ran, bool_and(coalesce(returned_sqlstate =3D '22025', false)) AS oracle_all_rejected FROM bugseer_postgres_00013_like_escape_results; ROLLBACK; Actual result ------------- case_name | returned_sqlstate ------------------+------------------- empty_default | nonempty_default | 22025 empty_custom | nonempty_custom | 22025 (4 rows) all_cases_ran | oracle_all_rejected ---------------+--------------------- t | f (1 row) Expected result --------------- Every pattern ending in its active escape character should raise SQLSTATE 22025, regardless of whether the input string is empty or nonempty. All four returned_sqlstate values should therefore be 22025 and oracle_all_rejected should be true. Additional information ---------------------- The issue was reproduced on PostgreSQL 20devel, PostgreSQL 18.6, and PostgreSQL 17.11.