In a postgres database I have a string field code in orders table. The field contains values like 'COA-38-A', 'EFILLDIRT' and 'HE60LS-A'. There is a form on UI to filter orders based on code and only integer values are allowed in the field.
The query should filter the orders by integer values in the code field i.e if 30 is entered, the query should return orders with code 'COA-38-A' and 'HE60LS-A' because the query contains >=
I tried adding ::integer in the query:
Order.where('code::integer >= ?', params[:code])
but got the following error:
PG::InvalidTextRepresentation: ERROR: invalid input syntax for integer
Is there any way to filter by only integer values?
COA-3A-8>= 30?..regexp_replace(code, '[^0-9]+', '', 'g')should get all digits for you