as the title states:
I have a select query, which I’m trying to “order by” a field which contains numbers, the thing is this numbers are really strings starting with 0s, so the “order by” is doing this…
...
10
11
12
01
02
03
...
Any thoughts?
EDIT: if I do this: “…ORDER BY (field+1)” I can workaround this, because somehow the string is internally being converted to integer. Is this the a way to “officially” convert it like C’s atoi?
You can use
CASThttp://www.sqlite.org/lang_expr.html#castexpr to cast the expression to an Integer.Well thats interesting, though I dont know how many
DBMSsupport such an operation so I don’t recommend it just in case you ever need to use a different system that doesn’t support it, not to mention you are adding an extra operation, which can affect performance, though you also do thisORDER BY (field + 0)Im going to investigate the performancetaken from the sqlite3 docs:
I was curios so I ran some benchmarks:
As we can see its a bit slower though not by much, interesting.