Re: select * from test where name like 'co_%'

From: "sivapostgres(at)yahoo(dot)com" <sivapostgres(at)yahoo(dot)com>
To: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: select * from test where name like 'co_%'
Date: 2020-03-10 13:05:20
Message-ID: 1984187071.3080276.1583845520147@mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Thanks.  Got it.
On Tuesday, 10 March, 2020, 06:30:27 pm IST, Paul Foerster <paul(dot)foerster(at)gmail(dot)com> wrote:

Hi,

an underscore matches a single character, any character. You'd have to
escape it and tell the query what the escape character is if you want
it to be treated as a standard character:

db=# create table t(t text);
CREATE TABLE
db=# insert into t(t) values ('fox'), ('fo_'), ('fo_x');
INSERT 0 3
db=# select * from t;
  t
------
fox
fo_
fo_x
(3 rows)

db=# select * from t where t like 'fo_%';
  t
------
fox
fo_
fo_x
(3 rows)

db=# select * from t where t like 'fo\_%' escape '\';
  t
------
fo_
fo_x
(2 rows)

Cheers,
Paul

On Tue, Mar 10, 2020 at 1:49 PM sivapostgres(at)yahoo(dot)com
<sivapostgres(at)yahoo(dot)com> wrote:
>
> Hello,
>
> What returns when I run a query like this;
>
> Select * from test where name like 'co_%';
>
> I expect anything that starts with 'co_' and NOT 'co' only.  Am I right?  But I get every names that starts with 'co'. Why ?
>
> Happiness Always
> BKR Sivaprakash
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2020-03-10 14:54:16 Re: How to discover what table is
Previous Message Paul Foerster 2020-03-10 12:59:55 Re: select * from test where name like 'co_%'