Re: BUG #4574: LIKE fails on non-varying character with no wildcards - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #4574: LIKE fails on non-varying character with no wildcards
Date
Msg-id 14585.1228834200@sss.pgh.pa.us
Whole thread Raw
In response to BUG #4574: LIKE fails on non-varying character with no wildcards  ("Nat!" <nat@mulle-kybernetik.com>)
List pgsql-bugs
"Nat!" <nat@mulle-kybernetik.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

pgsql-bugs by date:

Previous
From: "Nat!"
Date:
Subject: BUG #4574: LIKE fails on non-varying character with no wildcards
Next
From: "Paul Ramsey"
Date:
Subject: Re: [postgis-devel] RE: BUG #4567: Clustering on GIST INDEX clobbers records in table intermittently