Re: LIKE, "=" and fixed-width character fields

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Richard Huxton <dev(at)archonet(dot)com>
Cc: Dmitry Teslenko <dteslenko(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: LIKE, "=" and fixed-width character fields
Date: 2008-11-10 15:27:32
Message-ID: 6610.1226330852@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Richard Huxton <dev(at)archonet(dot)com> writes:
> Dmitry Teslenko wrote:
>> When <operator> is LIKE no records matches query, when <operator> is =
>> my record matches query. Why? And Does this behavior varies from
>> PostgreSQL 7.4 to 8.1?

> You're comparing a 3-character value '111' of type text to a
> 10-character one (whatever is in field1). That's probably not a sensible
> thing to do. You haven't got '111' as a value, you've got '111' with 7
> trailing spaces. Search for that and you'll find it.

Better yet: use varchar(n) not character(n). character(n) has no
redeeming social value whatsoever.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gerhard Heift 2008-11-10 15:31:31 Logging in function with exception
Previous Message Andrus 2008-11-10 15:18:22 Re: Optimizing IN queries