How to treat numbers within strings as numbers when sorting ("A3" sorts before "A10", not after)
20
votes
3
answers
12986
views
For all of these queries:
SELECT label FROM personal.storage_disks ORDER BY label ASC;
SELECT label FROM personal.storage_disks ORDER BY label COLLATE "C" ASC;
SELECT label FROM personal.storage_disks ORDER BY label COLLATE "POSIX" ASC;
SELECT label FROM personal.storage_disks ORDER BY label COLLATE "default" ASC;
The output is always:
DISK 1, DISK 10, DISK 2, DISK 3, [...]
But, I want and expect: DISK 1, DISK 2, DISK 3, [...] DISK 10
I'm out of collations to try now according to SELECT * FROM pg_collation;
... unless I'm supposed to use one of the many really weird ones with cryptic names. (I even tried a bunch of those with the same result.)
Please note that I've read the existing seemingly related SE questions as well as many articles on SORT BY
, but they didn't help and didn't clear up anything for me.
I'm using PostgreSQL 12.4
Asked by user15080516
(745 rep)
Feb 11, 2021, 01:47 PM
Last activity: Feb 19, 2021, 07:14 PM
Last activity: Feb 19, 2021, 07:14 PM