Re: char columns, space padding, and the "like" operator

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Haszlakiewicz, Eric" <EHASZLA(at)transunion(dot)com>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: char columns, space padding, and the "like" operator
Date: 2009-02-02 21:38:55
Message-ID: 8609.1233610735@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces

"Haszlakiewicz, Eric" <EHASZLA(at)transunion(dot)com> writes:
> Once I realized that the value in the table actually got extended to
> 'SOMEVALUE ', things started making sense, since the equivalent quick
> select is actually:
> select 'SOMEVALUE ' like 'SOME% %';

> Unfortunately, my app has a whole bunch of places where it uses
> constructs like this against char columns. Other databases (such as
> Informix), automatically strip spaces off char column so queries like
> the above behave in a more intuitive fashion.

Cast the char(n) column to text or varchar, and it should work more
like you're expecting.

regards, tom lane

In response to

Responses

Browse pgsql-interfaces by date

  From Date Subject
Next Message Haszlakiewicz, Eric 2009-02-02 22:07:43 Re: char columns, space padding, and the "like" operator
Previous Message Haszlakiewicz, Eric 2009-02-02 21:00:33 char columns, space padding, and the "like" operator