问题描述:

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?

网友答案:

Purely a guess, but maybe:

MyModel.order("(data ->> 'position')::Integer ASC").each {|x| puts x.position}
相关阅读:
Top