BUG #2309: Wrong string comparison

Lists: pgsql-bugs
From: "Yury Don" <yura(at)vpcit(dot)ru>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #2309: Wrong string comparison
Date: 2006-03-09 14:00:53
Message-ID: 20060309140053.ED78CF0B08@svr2.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 2309
Logged by: Yury Don
Email address: yura(at)vpcit(dot)ru
PostgreSQL version: 8.1.3
Operating system: Linux (Debian)
Description: Wrong string comparison
Details:

Looks like string comparison operators ignore spaces isnside of string.
Because of this sorting on text fields is wrong.

mdb=# select 'a z'::text>'ad'::text;
?column?
----------
t


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Yury Don" <yura(at)vpcit(dot)ru>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2309: Wrong string comparison
Date: 2006-03-10 00:48:17
Message-ID: 29095.1141951697@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

"Yury Don" <yura(at)vpcit(dot)ru> writes:
> Looks like string comparison operators ignore spaces isnside of string.

It's not wrong, it's just following the rules of the locale. You should
initdb the database with LANG=C if you want plain ASCII sorting.

regards, tom lane


From: Volkan YAZICI <yazicivo(at)ttnet(dot)net(dot)tr>
To: Yury Don <yura(at)vpcit(dot)ru>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2309: Wrong string comparison
Date: 2006-03-10 07:36:11
Message-ID: 20060310073611.GB248@alamut
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

Hi,

On Mar 09 02:00, Yury Don wrote:
> Looks like string comparison operators ignore spaces isnside of string.
> Because of this sorting on text fields is wrong.
>
> mdb=# select 'a z'::text>'ad'::text;
> ?column?
> ----------
> t

PostgreSQL relies on your locale for collation. Therefore, first you
need to check if your locale settings are working. For instance:

$ TEXT="a z\nad"
$ echo -e $TEXT | LC_COLLATE=tr_TR.iso88599 sort
ad
a z
$ echo -e $TEXT | LC_COLLATE=C sort
a z
ad

Regards.


From: Yury Don <yura(at)vpcit(dot)ru>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #2309: Wrong string comparison
Date: 2006-03-10 07:57:30
Message-ID: 200603101257.30717.yura@vpcit.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-bugs

On Friday 10 March 2006 12:36, Volkan YAZICI wrote:
> Hi,
>
> On Mar 09 02:00, Yury Don wrote:
> > Looks like string comparison operators ignore spaces isnside of string.
> > Because of this sorting on text fields is wrong.
> >
> > mdb=# select 'a z'::text>'ad'::text;
> > ?column?
> > ----------
> > t
>
> PostgreSQL relies on your locale for collation. Therefore, first you
> need to check if your locale settings are working. For instance:
>
> $ TEXT="a z\nad"
> $ echo -e $TEXT | LC_COLLATE=tr_TR.iso88599 sort
> ad
> a z
> $ echo -e $TEXT | LC_COLLATE=C sort
> a z
> ad
>
>
> Regards.
>

My locale is KOI8-R and sorting in PostgreSQL corresponds to sorting in
locale. I just didn't expect that sorting will be this way ...

--
Best regards,
Yury Don