Re: Like Command returning wrong result set

From: Christophe Pettus <xof(at)thebuild(dot)com>
To: "Tchouante, Merlin" <mtchouan(at)umaryland(dot)edu>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Like Command returning wrong result set
Date: 2021-08-05 14:05:13
Message-ID: 595A741D-8D12-4FB8-8794-28D3319EE2CD@thebuild.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> On Aug 5, 2021, at 07:00, Tchouante, Merlin <mtchouan(at)umaryland(dot)edu> wrote:
>
> Hello group,
>
> I’m writing a script and a bit confused on the results with the like command.
>
> gm.title like 'CP_%'
>
> The above command gives me records with titles like CP_40, CP_2, CP_23, etc.
>
> gm.title like '%_CT'

Somewhat confusingly, '_' is the single-character wildcard for SQL's LIKE operation:

xof=# SELECT 'A' LIKE '_';
?column?
----------
t
(1 row)

You can escape it to search for it literally:

xof=# SELECT '_' LIKE '\_';
?column?
----------
t
(1 row)

xof=# SELECT 'A' LIKE '\_';
?column?
----------
f
(1 row)

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Zied Kharrat 2021-08-05 14:08:58 Show table and columns with null value and count
Previous Message Pavel Stehule 2021-08-05 14:05:07 Re: Like Command returning wrong result set