On Sat, Oct 25, 2003 at 08:19:49PM -0700, Lynn.Tilby@asu.edu wrote:
...
> Could you explain to a newbie WHY the like and % at
> the end of the literal works when the normal select does
> not?
> > > ZRAN |2003-10-03| 20031003| 731491| 20.25| 21.
12345678
From that row, it looks as though your table definition says the first
column is a CHAR(8), rather than say varchar(8) or text. This means that
ZRAN is padded to 8 characters with spaces:
test=# create table zran (a char(8), b varchar(8), c text);
CREATE TABLE
test=# insert into zran values ('ZRAN','ZRAN','ZRAN');
INSERT 28334686 1
test=# select * from zran;
a | b | c
----------+------+------
ZRAN | ZRAN | ZRAN
(1 row)
test=# select * from zran where a='ZRAN ';
a | b | c
----------+------+------
ZRAN | ZRAN | ZRAN
(1 row)
Because we were guessing your table definition, we couldn't just add 4 spaces
after ZRAN, so we suggested "where a like 'ZRAN%'". LIKE understands % to
mean "0 or more anything", so it would match 'ZRANNN' too, which might not
be what you want.. Most sensible might be to change your table definition..
Cheers,
Patrick