This is probably due to the formatReadableSize being applied before the results get displayed, but it would be super nice if order by still ordered by the original values.
this is contradicts SQL.
you can use
select formatReadableSize(size)
...
order by size
It is not a bug. formatReadableSize return strings, so they are ordered as strings.
Use the approach shown in @den-crane 's answer,
@abraithwaite
Consider more simple example:
SELECT toString(number) AS x FROM numbers(100) ORDER BY x
It's obvious that this query sort data alphabetically (by String value). And it is the only way it should work.
formatReadableSize is similar. This function returns String data type, not some String but sort numerically magic.
Thanks! I was aware that it was being converted to a string but didn't realize I could order by the original field. Works great!
Most helpful comment
this is contradicts SQL.
you can use
select formatReadableSize(size)
...
order by size