Re: LIKE with no wildcards problem

Lists: pgsql-novice
From: "John J(dot) Allison" <john(at)joss(dot)ucar(dot)edu>
To: pgsql-novice(at)postgresql(dot)org
Subject: LIKE with no wildcards problem
Date: 2002-02-27 23:58:39
Message-ID: 200202272358.QAA00442@wind.joss.ucar.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

When doing a select with a LIKE in the where clause,
I always get 0 rows if I do not use a wildcard [_%].
LIKE should act like = in this case (and the docs say so).
A select without a from correctly returns 't'.
I am using PostgreSQL 7.1.3 on Solaris.

What am I missing?
Should I ask pgsql-sql?

Thanks,

John Allison
john(at)joss(dot)ucar(dot)edu

catalog^> create table foo ( bar char(8) )
CREATE

catalog^> insert into foo values ( 'abc' )
INSERT 38413 1

catalog^> insert into foo values ( '2.20' )
INSERT 38414 1

catalog^> select * from foo
bar
----------
abc
2.20
(2 rows)

catalog^> select * from foo where bar like 'abc'
bar
-----
(0 rows)

catalog^> select * from foo where bar like 'abc%'
bar
----------
abc
(1 row)

catalog^> select 'abc' like 'abc'
?column?
----------
t
(1 row)


From: Andrew McMillan <andrew(at)catalyst(dot)net(dot)nz>
To: "John J(dot) Allison" <john(at)joss(dot)ucar(dot)edu>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: LIKE with no wildcards problem
Date: 2002-03-05 21:57:43
Message-ID: 1015365463.993.2859.camel@kant.mcmillan.net.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-novice

On Thu, 2002-02-28 at 12:58, John J. Allison wrote:
> When doing a select with a LIKE in the where clause,
> I always get 0 rows if I do not use a wildcard [_%].
> LIKE should act like = in this case (and the docs say so).
> A select without a from correctly returns 't'.
> I am using PostgreSQL 7.1.3 on Solaris.
>
> What am I missing?
> Should I ask pgsql-sql?
>
> Thanks,
>
> John Allison
> john(at)joss(dot)ucar(dot)edu
>
>
> catalog^> create table foo ( bar char(8) )
> CREATE
>
> catalog^> insert into foo values ( 'abc' )
> INSERT 38413 1
>
> catalog^> insert into foo values ( '2.20' )
> INSERT 38414 1
>
> catalog^> select * from foo
> bar
> ----------
> abc
> 2.20
> (2 rows)
>
> catalog^> select * from foo where bar like 'abc'
> bar
> -----
> (0 rows)

select * from foo where bar like 'abc ';

char(8) is right-padded with spaces. Use TEXT, or VARCHAR if you don't
want this sort of effect.

Regards,
Andrew.
>
> catalog^> select 'abc' like 'abc'
> ?column?
> ----------
> t
> (1 row)

This one will be type text, since no types are specified and that is
what PostgreSQL will prefer internally.

Cheers,
Andrew.
--
--------------------------------------------------------------------
Andrew @ Catalyst .Net.NZ Ltd, PO Box 11-053, Manners St, Wellington
WEB: http://catalyst.net.nz/ PHYS: Level 2, 150-154 Willis St
DDI: +64(4)916-7201 MOB: +64(21)635-694 OFFICE: +64(4)499-2267
Are you enrolled at http://schoolreunions.co.nz/ yet?