Rails PostgreSQL sort by integer value of string Rails PostgreSQL sort by integer value of string postgresql postgresql

Rails PostgreSQL sort by integer value of string


With PostgreSQL you will want to cast your string to integer/float/decimal (after you decide you 100% will not go and change the column type to correct one):

MyModel.order('price::integer DESC')

Consider this answer to make it work fast.