Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mBe0K-00044i-SL for pgsql-sql@arkaria.postgresql.org; Thu, 05 Aug 2021 14:05:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mBe0J-0006n1-Nv for pgsql-sql@arkaria.postgresql.org; Thu, 05 Aug 2021 14:05:47 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mBdzq-0002QX-0F for pgsql-sql@lists.postgresql.org; Thu, 05 Aug 2021 14:05:18 +0000 Received: from smtp105.ord1c.emailsrvr.com ([108.166.43.105]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mBdzn-00021Q-MC for pgsql-sql@postgresql.org; Thu, 05 Aug 2021 14:05:17 +0000 X-Auth-ID: xof@thebuild.com Received: by smtp6.relay.ord1c.emailsrvr.com (Authenticated sender: xof-AT-thebuild.com) with ESMTPSA id 7AF19A01CE; Thu, 5 Aug 2021 10:05:14 -0400 (EDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.7\)) Subject: Re: Like Command returning wrong result set From: Christophe Pettus In-Reply-To: Date: Thu, 5 Aug 2021 07:05:13 -0700 Cc: "pgsql-sql@postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: <595A741D-8D12-4FB8-8794-28D3319EE2CD@thebuild.com> References: To: "Tchouante, Merlin" X-Mailer: Apple Mail (2.3608.120.23.2.7) X-Classification-ID: 2cc295b3-9a7e-48f5-b504-140e9acafaba-1-1 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > On Aug 5, 2021, at 07:00, Tchouante, Merlin = wrote: >=20 > Hello group, > =20 > I=E2=80=99m writing a script and a bit confused on the results with = the like command. > =20 > gm.title like 'CP_%' > =20 > The above command gives me records with titles like CP_40, CP_2, = CP_23, etc. > =20 > gm.title like '%_CT' Somewhat confusingly, '_' is the single-character wildcard for SQL's = LIKE operation: xof=3D# SELECT 'A' LIKE '_'; ?column?=20 ---------- t (1 row) You can escape it to search for it literally: xof=3D# SELECT '_' LIKE '\_'; ?column?=20 ---------- t (1 row) xof=3D# SELECT 'A' LIKE '\_'; ?column?=20 ---------- f (1 row)