Re: BUG #4574: LIKE fails on non-varying character with no wildcards

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Nat!" <nat(at)mulle-kybernetik(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #4574: LIKE fails on non-varying character with no wildcards
Date: 2008-12-09 14:50:00
Message-ID: 14585.1228834200@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Nat!" <nat(at)mulle-kybernetik(dot)com> writes:
> create temporary table foo ( nummer character(12) );

> insert into foo ( nummer) values( '1848' ) ;

> select count(*) from foo where nummer = '1848' ;
> -- returns 1

> select count(*) from foo where nummer like '1848' ;
> -- returns 0

The trailing spaces are significant when doing LIKE on a char(n) column.

regression=# select '1848'::character(12) like '1848';
?column?
----------
f
(1 row)

regression=# select '1848'::character(12) like '1848 ';
?column?
----------
t
(1 row)

(By and large, my advice for all such cases is "don't use char(n)".
It has no redeeming social value whatever.)

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2008-12-09 22:11:56 Re: download PostgreSQL 8.0.2
Previous Message Nat! 2008-12-09 14:07:03 BUG #4574: LIKE fails on non-varying character with no wildcards