Re: BUG #5877: problem with wild char used in where clause

From: "Kevin Grittner" <Kevin(dot)Grittner(at)wicourts(dot)gov>
To: "Savita" <savita(dot)halli(at)gmail(dot)com>,<pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #5877: problem with wild char used in where clause
Date: 2011-02-10 19:45:37
Message-ID: 4D53EC01020000250003A7BD@gw.wicourts.gov
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Savita" <savita(dot)halli(at)gmail(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Mauricio Agustin Roubineau 2011-02-10 22:38:34 BUG #5879: PostgreSQL can not load my data folder
Previous Message hubert depesz lubaczewski 2011-02-10 19:40:44 Re: BUG #5877: problem with wild char used in where clause