views:

43

answers:

1

Hi,

I have the following named_scope which works fine in MySQL and sqlite but bombs in Postgres:

course.rb

named_scope :current, :conditions => ['start < ? AND end > ? ', Time.now, Time.now], :order => 'start ASC'

Then I just call:

Course.current

I get the error:

PGError: ERROR: syntax error at or near "end" LINE 1: ... WHERE (start < '2010-03-17 14:03:24.995746' AND end > '201... ^ : SELECT count(*) AS count_all FROM "courses" WHERE (start < '2010-03-17 14:03:24.995746' AND end > '2010-03-17 14:03:24.995748' )

My google-fu is failing me so I'm hoping Stack Overflow won't. Any ideas on how to make that scope Postgres-friendly? Thanks,

Drew

+1  A: 

END is a keyword, you have to use another name or place it between double quotes "end".

If you use double quotes around the columnname and use this code also for MySQL, tell MySQL to accept double quotes as object identifier by setting the correct SQL MODE: ANSI_QUOTES

Frank Heikens
That was it! I renamed the column from "end" to "finish" and now we're all set. Thanks so much for the help!
Drew Banning