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

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

Dmitry Teslenko wrote:
>> richardh=> SELECT * FROM chartbl WHERE c LIKE '111';
>> c
>> ---
>> (0 rows)
>>
>> richardh=> SELECT * FROM chartbl WHERE c LIKE '111 ';
>> c
>> ------------
>> 111
>> (1 row)
>>
>> richardh=> SELECT * FROM chartbl WHERE c LIKE '111%';
>> c
>> ------------
>> 111
>> (1 row)
>>
>
> '111%' would also match '1111' and '111anything', wouldn't it?

Yes.

I'm guessing what you actually want is varchar(10) rather than char(10)
as a type.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Diego Manilla Suárez 2008-11-11 08:56:15 Question about weird construct
Previous Message Dmitry Teslenko 2008-11-11 07:52:17 Re: LIKE, "=" and fixed-width character fields