Re: Sorting Discrepancy in PostgreSQL 14.13 - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Sorting Discrepancy in PostgreSQL 14.13
Date
Msg-id 2358737.1731644734@sss.pgh.pa.us
Whole thread Raw
In response to Re: Sorting Discrepancy in PostgreSQL 14.13  (Tomas Vondra <tomas@vondra.me>)
List pgsql-bugs
Tomas Vondra <tomas@vondra.me> writes:
> On 11/14/24 13:49, [3반]김민지_4904 wrote:
>> I'm doubtful this is a collation issue, as most collations basically
>> respect ASCII order.

> This is 99.999% due to the collation, so which collations are being used
> on these systems? Also, I don't get this "incorrect" behavior on 14.13,
> it behaves the same as 17 for me, producing the expected result.

It surely is a collation issue.  Using a glibc-based system, I get

u8=# CREATE TABLE t0 (c0 TEXT);
CREATE TABLE
u8=# INSERT INTO t0 (c0) VALUES ('-10'), ('20'), ('-5'), ('15'), ('-25');
INSERT 0 5
u8=# select * from t0 order by c0 collate "C";
 c0  
-----
 -10
 -25
 -5
 15
 20
(5 rows)

u8=# select * from t0 order by c0 collate "en_US";
 c0  
-----
 -10
 15
 20
 -25
 -5
(5 rows)

(In point of fact, most glibc collations do NOT "respect ASCII order".
They tend to ignore punctuation until it's needed as a tiebreaker.)

So this is surely down to the PG 14.13 installation having a different
default collation than whatever it's compared to, which most likely
is caused by having run initdb with a different locale environment.

            regards, tom lane



pgsql-bugs by date:

Previous
From: PG Bug reporting form
Date:
Subject: BUG #18710: "pg_get_viewdef" triggers assertions in special scenarios
Next
From: Tender Wang
Date:
Subject: Re: BUG #18705: Segmentation fault when create brin index on user-defined type.