I have a Mariadb table with a varchar field. I’m having trouble sorting it. I’m sure this has to do with the varchar status but I don’t know what is the best way to convert it during the API database pull.
Hi.
Sorting works fine in Wappler query builder.
What is the data that you have as varchar in db, what is the sorting you get and what is the expected output?
If you need to convert/cast the column, you will have to use custom query.
As an alternative to using custom queries, views or extra APIs etc, you could create an extra field specifically for sorting, defined as a virtual column, eg:
right(concat('0000',numberAsText),5)
… where numberAsText is your existing field. Obviously, you might have to tweak the expression but this would result in:
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
If defined as VIRTUAL as opposed to STORED, the extra field wouldn’t take any extra space. (I don’t know if this affects sorting speed.)