Unexpected behavior sorting strings - Mailing list pgsql-general

From Jimmy Thrasher
Subject Unexpected behavior sorting strings
Date
Msg-id 410dddd6-bc66-48ca-ab9d-13889d94b62c@www.fastmail.com
Whole thread Raw
Responses Re: Unexpected behavior sorting strings
Re: Unexpected behavior sorting strings
List pgsql-general
I'm seeing some unexpected behavior when sorting some strings, and it indicates I don't fully understand how postgresql
stringsorting 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



pgsql-general by date:

Previous
From: Pavel Stehule
Date:
Subject: Re: Performance degradation if query returns no rows and columnexpression is used after upgrading to 12
Next
From: Adrian Klaver
Date:
Subject: Re: Best method to display table information in predefined formats