statamic / eloquent-driver

Provides support for storing your Statamic data in a database, rather than flat files.
https://statamic.dev/tips/storing-content-in-a-database
MIT License
104 stars 73 forks source link

Sorting does not work for numeric fields #153

Closed helloiamlukas closed 1 year ago

helloiamlukas commented 1 year ago

Description

When sorting numeric fields, the order of the results is not as expected.

Expected sorting order

1
3
22

Actual sorting order

1
22
3

This problem is caused by the fact that the column will be converted to a string when running the query:

order by "data"->>'number' asc

To solve this, the query should look like this (for numeric fields):

order by "data"->'number' asc