pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedLIKE with no wildcards problem
4+ messages / 4 participants
[nested] [flat]
* LIKE with no wildcards problem
@ 2002-02-28 18:54 John J. Allison <john@joss.ucar.edu>
0 siblings, 3 replies; 4+ messages in thread
From: John J. Allison @ 2002-02-28 18:54 UTC (permalink / raw)
To: pgsql-sql
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?
Thanks,
John Allison
john@joss.ucar.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)
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: LIKE with no wildcards problem
@ 2002-02-28 19:28 Josh Berkus <josh@agliodbs.com>
parent: John J. Allison <john@joss.ucar.edu>
2 siblings, 0 replies; 4+ messages in thread
From: Josh Berkus @ 2002-02-28 19:28 UTC (permalink / raw)
To: John J. Allison <john@joss.ucar.edu>; pgsql-sql
John,
> 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?
> catalog^> create table foo ( bar char(8) )
> CREATE
>
You created the column bar as CHAR(8), which means what's actually
being stored is "abc " not "abc". I think you want to use VARCHAR
instead.
-Josh
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: LIKE with no wildcards problem
@ 2002-02-28 19:36 Ian Barwick <barwick@gmx.net>
parent: John J. Allison <john@joss.ucar.edu>
2 siblings, 0 replies; 4+ messages in thread
From: Ian Barwick @ 2002-02-28 19:36 UTC (permalink / raw)
To: John J. Allison <john@joss.ucar.edu>; pgsql-sql
On Thursday 28 February 2002 19:54, 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?
>
> Thanks,
>
> John Allison
> john@joss.ucar.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)
How about:
catalog^> SELECT bar, length(bar) from foo;
bar | length
----------+--------
abc | 8
2.20 | 8
(2 rows)
The CHARACTER type is always padded to the maximum length, viz:
http://www.postgresql.org/idocs/index.php?datatype-character.html
Ian Barwick
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: LIKE with no wildcards problem
@ 2002-02-28 19:46 Ross J. Reedstrom <reedstrm@rice.edu>
parent: John J. Allison <john@joss.ucar.edu>
2 siblings, 0 replies; 4+ messages in thread
From: Ross J. Reedstrom @ 2002-02-28 19:46 UTC (permalink / raw)
To: John J. Allison <john@joss.ucar.edu>; +Cc: pgsql-sql
On Thu, Feb 28, 2002 at 11:54:02AM -0700, 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?
The whitespace. Your field is of type CHAR(n), which pads all strings
to the defined width. This behavior is required by the standard. Try
using VARCHAR or TEXT instead.
Ross
>
> Thanks,
>
> John Allison
> john@joss.ucar.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)
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2002-02-28 19:46 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-02-28 18:54 LIKE with no wildcards problem John J. Allison <john@joss.ucar.edu>
2002-02-28 19:28 ` Josh Berkus <josh@agliodbs.com>
2002-02-28 19:36 ` Ian Barwick <barwick@gmx.net>
2002-02-28 19:46 ` Ross J. Reedstrom <reedstrm@rice.edu>
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