Bug #16348 Natural Sorting in MySQL ?
Submitted: 10 Jan 2006 18:56 Modified: 10 Jan 2006 20:32
Reporter: Apachez Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server Severity:S4 (Feature request)
Version: OS:
Assigned to: CPU Architecture:Any

[10 Jan 2006 18:56] Apachez
Description:
I stumbled upon this site recently and got the idea that this would be a nice feature if it could be implemented in MySQL's sort engine: http://sourcefrog.net/projects/natsort/

Example from the site in question which explains what "Natural Sort" is all about:

"
Computer string sorting algorithms generally don't order strings containing numbers in the same way that a human would do. Consider: 

rfc1.txt
rfc2086.txt
rfc822.txt

It would be more friendly if the program listed the files as 

rfc1.txt
rfc822.txt
rfc2086.txt

Filenames sort properly if people insert leading zeros, but they don't always do that. 
"

Perhaps it could be as an extra value to the ORDER BY like:

SELECT * FROM t1 ORDER BY textcol ASC, datecol DESC;

vs

SELECT * FROM t1 ORDER BY textcol NATURAL ASC, datecol DESC;

(or SELECT * FROM t1 ORDER BY textcol ASC NATURAL, datecol DESC;)

So what does MySQL think about this proposal, is it plausible or busted (the mythbusters way - poor, poor Buster) ?

How to repeat:
This is a feature request...
[10 Jan 2006 20:32] Peter Gulutzan
This is a duplicate of bug#1588: "natural" sorting.

There has been discussion of this from time to time, e.g.
http://forums.mysql.com/read.php?10,34908,35157,quote=1

MySQL's Dean Ellis once wrote a UDF -- see
http://www.deanellis.com/index.php?p=11
[18 Feb 2007 19:53] Peter Gulutzan
Markus Popp had a tip on a related matter in his blog:
" Sorting of numeric values mixed with alphanumeric values":
http://db4free.blogspot.com/2006/06/sorting-of-numeric-values-mixed-with.html