Re: BUG #5877: problem with wild char used in where clause - Mailing list pgsql-bugs

From Kevin Grittner
Subject Re: BUG #5877: problem with wild char used in where clause
Date
Msg-id 4D53EC01020000250003A7BD@gw.wicourts.gov
Whole thread Raw
In response to BUG #5877: problem with wild char used in where clause  ("Savita" <savita.halli@gmail.com>)
List pgsql-bugs
"Savita" <savita.halli@gmail.com> wrote:

> When I ran query to get the ids which ends with B1
> select id from table where id like '%B1'
> does not return me any rows. Should it be not returning row with
> id AB1? Is there known issue?

Oh, I did have one more thought after I posted -- what is the data
type of the id column.  If it is character(n), also specified as
char(n), you would need to include trailing spaces or a wildcard at
the end of your string.  For all purposes, including pattern
matching, char(n) values are considered to be padded with space
characters to their declared length.  So if the id was char(4) the
'%B1' would be considered a match to AAB1 but not AB1.

Use of char(n) columns is generally discouraged because the
semantics required by the standard can be rather surprising.
Consider varchar(n) or text instead.

-Kevin

pgsql-bugs by date:

Previous
From: hubert depesz lubaczewski
Date:
Subject: Re: BUG #5877: problem with wild char used in where clause
Next
From: "Dag Lem"
Date:
Subject: BUG #5876: Incorrectly reported column value