Re: select * from test where name like 'co_%' - Mailing list pgsql-general

From Paul Foerster
Subject Re: select * from test where name like 'co_%'
Date
Msg-id CABNMRRwkfwz46w3_=8saYxUE39KTLhqEOGaDA5UKrjwYNqcoCQ@mail.gmail.com
Whole thread Raw
In response to Re: select * from test where name like 'co_%'  ("sivapostgres@yahoo.com" <sivapostgres@yahoo.com>)
Responses Re: select * from test where name like 'co_%'  ("sivapostgres@yahoo.com" <sivapostgres@yahoo.com>)
List pgsql-general
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@yahoo.com
<sivapostgres@yahoo.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
>



pgsql-general by date:

Previous
From: Kenneth Marshall
Date:
Subject: Re: select * from test where name like 'co_%'
Next
From: "sivapostgres@yahoo.com"
Date:
Subject: Re: select * from test where name like 'co_%'