Tuesday, 15 March 2011

postgresql - Rails where word count in string column greater than? -



postgresql - Rails where word count in string column greater than? -

i need filter records how many words exist in column.

the next works, of course of study returns character count...i need word count

flight.where("length(route) > 3")

is there rails way (or way) this?

this getting closer (its right out of rails docs) results in error

flight.where("array_length(route, 1) >= 3") error: aggregate functions not allowed in error: function array_length(character varying, integer) not exist

docs suggest using having .. not working

flight.having("route.count > ?", 2)

you can utilize split create array string words spaced whitespace within string , count total.

flight.select(:route).select { |flight| flight.route.split(" ").length > 3 }

postgresql ruby-on-rails-4

No comments:

Post a Comment