Re: no records returned

From: Patrick Welche <prlw1(at)newn(dot)cam(dot)ac(dot)uk>
To: Lynn(dot)Tilby(at)asu(dot)edu
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: no records returned
Date: 2003-10-26 13:15:26
Message-ID: 20031026131526.C11519@quartz.newn.cam.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sat, Oct 25, 2003 at 08:19:49PM -0700, Lynn(dot)Tilby(at)asu(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Yonatan Goraly 2003-10-26 13:28:21 Re: Slow performance with no apparent reason
Previous Message Vadim Chekan 2003-10-26 10:43:58 Casing: bug?