From: Jimmy Thrasher <jimmy@jimmythrasher.com>
To: pgsql-general@postgresql.org
Subject: Unexpected behavior sorting strings
Date: Wed, 08 Apr 2020 10:35:32 -0400
Message-ID: <410dddd6-bc66-48ca-ab9d-13889d94b62c@www.fastmail.com> (raw)
I'm seeing some unexpected behavior when sorting some strings, and it indicates I don't fully understand how postgresql string sorting works.
As I understand it, postgresql sorts strings roughly like strcmp does: character by character based on encoding value.
In particular, I'm seeing the following. I would expect "< S" to come first, because "<" (0x3c) is less than ">" (0x3e).
```
supercatdev=# select unnest(array['> N', '< S']) as s order by s;
s
-----
> N
< S
(2 rows)
```
I've broken this down further:
```
supercatdev=# select '> N' < '< S';
?column?
----------
t
(1 row)
```
Am I missing something about how sorting works?
Metadata:
- postgresql 9.5.19, running on Ubuntu 16LTS
- encoding, collate, and ctype are all UTF8 or en_US.UTF-8, as appropriate
Thanks!
Jimmy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: jimmy@jimmythrasher.com
Subject: Re: Unexpected behavior sorting strings
In-Reply-To: <410dddd6-bc66-48ca-ab9d-13889d94b62c@www.fastmail.com>
References: <410dddd6-bc66-48ca-ab9d-13889d94b62c@www.fastmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox