Reputation: 21877
This search condition works fine in MySQL, and SQLite but fails in PostgreSQL:
CONTROLLER:
@inventories = Inventory.search(params[:search], params[:page])
MODEL:
def self.search
paginate :per_page => 10,
:page => page,
:conditions => ['part_number = ? OR item LIKE ? OR catalognumber LIKE ?', "#{search}", "%#{search}%", "%#{search}%"],
:order => 'item'
end
IT produces this error in HEROKU's PostgreSQL log:
ActiveRecord::StatementInvalid (PGError: ERROR: invalid input syntax for integer: ""
2011-06-11T20:25:46+00:00 app[web.1]: : SELECT * FROM "inventories" WHERE (part_number = E'' OR item LIKE E'' OR catalognumber LIKE E'') ORDER BY item LIMIT 10 OFFSET 0):
How can I fix this?
SOLUTION... This is an issue of using LIKE rather than ILIKE http://www.postgresql.org/docs/8.3/static/functions-matching.html
Upvotes: 1
Views: 359
Reputation: 78443
Presumably, one of those fields is expecting an integer, and Postgres is a lot less permissive on this front than MySQL. I shouldn't have any quotes. (It should be zero, or no field at all, instead.)
Upvotes: 1