pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedRe: select * from test where name like 'co_%'
4+ messages / 3 participants
[nested] [flat]
* Re: select * from test where name like 'co_%'
@ 2020-03-10 12:49 sivapostgres@yahoo.com <sivapostgres@yahoo.com>
0 siblings, 2 replies; 4+ messages in thread
From: sivapostgres@yahoo.com @ 2020-03-10 12:49 UTC (permalink / raw)
To: Postgresql General Group <pgsql-general@lists.postgresql.org>
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
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: select * from test where name like 'co_%'
@ 2020-03-10 12:54 Kenneth Marshall <ktm@rice.edu>
parent: sivapostgres@yahoo.com <sivapostgres@yahoo.com>
1 sibling, 0 replies; 4+ messages in thread
From: Kenneth Marshall @ 2020-03-10 12:54 UTC (permalink / raw)
To: sivapostgres@yahoo.com <sivapostgres@yahoo.com>; +Cc: Postgresql General Group <pgsql-general@lists.postgresql.org>
On Tue, Mar 10, 2020 at 12:49:01PM +0000, 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
Hi,
Check out the documentation:
https://www.postgresql.org/docs/12/functions-matching.html#FUNCTIONS-LIKE
You have 2 meta characters there. The '_' matches any character also.
Regards,
Ken
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: select * from test where name like 'co_%'
@ 2020-03-10 12:59 Paul Foerster <paul.foerster@gmail.com>
parent: sivapostgres@yahoo.com <sivapostgres@yahoo.com>
1 sibling, 1 reply; 4+ messages in thread
From: Paul Foerster @ 2020-03-10 12:59 UTC (permalink / raw)
To: sivapostgres@yahoo.com <sivapostgres@yahoo.com>; +Cc: Postgresql General Group <pgsql-general@lists.postgresql.org>
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
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: select * from test where name like 'co_%'
@ 2020-03-10 13:05 sivapostgres@yahoo.com <sivapostgres@yahoo.com>
parent: Paul Foerster <paul.foerster@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: sivapostgres@yahoo.com @ 2020-03-10 13:05 UTC (permalink / raw)
To: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Thanks. Got it.
On Tuesday, 10 March, 2020, 06:30:27 pm IST, Paul Foerster <paul.foerster@gmail.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@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
>
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2020-03-10 13:05 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-03-10 12:49 Re: select * from test where name like 'co_%' sivapostgres@yahoo.com <sivapostgres@yahoo.com>
2020-03-10 12:54 ` Kenneth Marshall <ktm@rice.edu>
2020-03-10 12:59 ` Paul Foerster <paul.foerster@gmail.com>
2020-03-10 13:05 ` sivapostgres@yahoo.com <sivapostgres@yahoo.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox