Reputation: 349
I have put up an app on Heroku that is running fine locally (using sqlite3 as the gem for the database in testing), and when I push to Heroku and try to run it I keep getting this error:
ActiveRecord::StatementInvalid (PG::Error: ERROR: syntax error at or near "order"
LINE 1: ...lery_url_id = 'k19fv2mytjEb_3gCezLeRA') ORDER BY `order` ASC ^
: SELECT "pictures".* FROM "pictures" WHERE (gallery_url_id = 'k19fv2mytjEb_3gCezLeRA') ORDER BY `order` ASC):
app/controllers/galleries_controller.rb:38:in `show'
Specifically on this line:
@pictures = Picture.find(:all, :conditions => [ 'gallery_url_id = ?', @gallery.url_id ], :order => "`order` ASC")
NOTE: order is a database field, not a SQL call or reference. So don't go telling me I am doing two orders. That would be silly. Unless somehow it is being parsed that way. Which would also be silly.
I understand that it is some issue from using SQLite in the local testing and PostgreSQL (pg) in the production environment. My question is what do I need to do to fix this? Is it due to a flag that I call in the find that is only supported by SQLite and not PostgreSQL?
Upvotes: 1
Views: 351
Reputation: 434915
Backticks for quoting identifiers are a MySQL-ism that SQLite also supports. The standard syntax (which PostgreSQL uses) for quoting identifiers is to use double quotes:
:order => '"order" ASC'
I'd recommend that you do two things as soon as possible:
"order"
column to something that isn't reserved.The second point is quite important. Database portability is a myth, there are so many little differences between databases that writing code that works the same in multiple databases is difficult and means writing your own portability layer (and no, ActiveRecord is not that portability layer). This minor quoting problem will probably be the first of many little issues.
Upvotes: 7