Reputation: 34013
I have a position
key defined in my JSONB column.
The values are treated as text, so the following query
MyModel.order("data ->> 'position' ASC").each {|x| puts x.position}
returns:
0
1
10
2
3
How can I treat position
as integer and order my model based on that?
Upvotes: 1
Views: 1824
Reputation: 52336
Purely a guess, but maybe:
MyModel.order("(data ->> 'position')::Integer ASC").each {|x| puts x.position}
Upvotes: 5