简体   繁体   中英

PostgreSQL Ruby Heroku Problems

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

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM