Re: LIKE, "=" and fixed-width character fields - Mailing list pgsql-general

From Tom Lane
Subject Re: LIKE, "=" and fixed-width character fields
Date
Msg-id 6610.1226330852@sss.pgh.pa.us
Whole thread Raw
In response to Re: LIKE, "=" and fixed-width character fields  (Richard Huxton <dev@archonet.com>)
Responses Re: LIKE, "=" and fixed-width character fields  ("Dmitry Teslenko" <dteslenko@gmail.com>)
List pgsql-general
Richard Huxton <dev@archonet.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

pgsql-general by date:

Previous
From: Richard Huxton
Date:
Subject: Re: LIKE, "=" and fixed-width character fields
Next
From: Gerhard Heift
Date:
Subject: Logging in function with exception