Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tBntw-006EMN-0t for pgsql-bugs@arkaria.postgresql.org; Fri, 15 Nov 2024 04:25:43 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1tBntr-007nas-GQ for pgsql-bugs@arkaria.postgresql.org; Fri, 15 Nov 2024 04:25:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tBntr-007nak-7z for pgsql-bugs@lists.postgresql.org; Fri, 15 Nov 2024 04:25:39 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tBnto-001wwz-Vv for pgsql-bugs@lists.postgresql.org; Fri, 15 Nov 2024 04:25:38 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 4AF4PYJ82358738; Thu, 14 Nov 2024 23:25:34 -0500 From: Tom Lane To: Tomas Vondra cc: =?UTF-8?B?WzPrsJhd6rmA66+87KeAXzQ5MDQ=?= , pgsql-bugs@lists.postgresql.org Subject: Re: Sorting Discrepancy in PostgreSQL 14.13 In-reply-to: <69c7ee62-f9de-4365-b325-7e493203a7ae@vondra.me> References: <69c7ee62-f9de-4365-b325-7e493203a7ae@vondra.me> Comments: In-reply-to Tomas Vondra message dated "Thu, 14 Nov 2024 15:48:36 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <2358736.1731644734.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Thu, 14 Nov 2024 23:25:34 -0500 Message-ID: <2358737.1731644734@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Tomas Vondra 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