I am trying to replicate the PostgreSQL sorting results for testing purposes.
Suppose you have a table temp
with a single column name
containing the following lines:
dolores et
dolor nemo
abc
zxc
Now run the following query:
SELECT * from temp ORDER BY name ASC
The sorted result is:
abc
dolores et
dolor nemo
zxc
However, the default implementation for sorting in programming languages will return it differently:
abc
dolor nemo
dolores et
zxc
In JavaScript:
["dolores et", "dolor nemo", 'abc' , 'zxc'].sort()
// returns ["abc", "dolor nemo", "dolores et", "zxc"]
I was wondering if there is an easy way to replicate the sorting result from the database in JavaScript (I am using NodeJS), so I can verify it in my tests. I believe I am missing something very simple here. Any help is appreciated.
I could try to use a function like this one to force the order in PostgreSQL, but I do not want that. My goal is to replicate the default behavior in JavaScript.