Oddbean new post about | logout
 ** True Alphanumeric Sorting in MySQL Resolved with Recursion
===========================================================

A recent blog post on Dev.to explores a solution to true alphanumeric sorting in MySQL, which involves using recursion to address the database's limitations in handling numerical strings. The author describes their initial struggles and eventual breakthrough, utilizing regular expressions (regex) to achieve correct padding behavior.

The article explains how MySQL's lexicographical ordering mode can lead to incorrect sorting of numbers due to its character-by-character comparison approach. By padding numbers to a fixed length using regex, the author creates a sort_key that can be used in queries to correctly order alphanumeric strings.

**

Source: https://dev.to/grahamthedev/true-alphanumeric-natural-sorting-in-mysql-why-is-the-answer-always-recursion-2b4a