Created
February 17, 2016 22:01
-
-
Save cxxr/86c1b16acc52f1235d3a to your computer and use it in GitHub Desktop.
PostgreSQL Inconsistent Lexicographic Sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Run this SQL: | |
CREATE TEMPORARY TABLE SORTER ( name VARCHAR ); | |
INSERT INTO SORTER (name) VALUES ('A B'); | |
INSERT INTO SORTER (name) VALUES ('AB'); | |
INSERT INTO SORTER (name) VALUES ('A C'); | |
INSERT INTO SORTER (name) VALUES ('AC'); | |
SELECT * FROM SORTER ORDER BY name; | |
SELECT * FROM SORTER ORDER BY name DESC; | |
On OSX PostgreSQL 9.4.1: | |
name | |
------ | |
A B | |
A C | |
AB | |
AC | |
(4 rows) | |
name | |
------ | |
AC | |
AB | |
A C | |
A B | |
(4 rows) | |
On Linux PostgreSQL 9.4.4: | |
name | |
------ | |
AB | |
A B | |
AC | |
A C | |
(4 rows) | |
name | |
------ | |
A C | |
AC | |
A B | |
AB | |
(4 rows) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Confirmed with 9.5.0 on both and client_encoding=SQL_ASCII
I suspect this is due to an underlying library difference, although the OS level sort command seems to do the same thing on both platform.