Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActiveRecord range condition with Time objects produces unquoted date strings in SQL

#4124

Rails 3.0.0.beta, the DBMS is PostgreSQL.
I don't know if this bug is related to ActiveRecord or PostgreSQL adaptor, however this is the issue:

I have a model "Flight" with a timestamp :takeoff_time column.

Normal range selects with numeric parameters work fine:

Flight.where(:pilot_id => 1..10).count SQL (11.2ms) SELECT COUNT(*) AS count_id FROM "flights" WHERE ("flights"."pilot_id" BETWEEN 1 AND 10)

Equal comparison with Time work fine:

Flight.where(:takeoff_time => Time::now).count SQL (0.5ms) SELECT COUNT(*) AS count_id FROM "flights" WHERE ("flights"."takeoff_time" = '2010-03-07 15:52:41.248325')

Ranges with Time with ... inclusion work fine:

Flight.where(:takeoff_time => Time::now...Time::now).count SQL (0.4ms) SELECT COUNT(*) AS count_id FROM "flights" WHERE ("flights"."takeoff_time" >= '2010-03-07 15:54:05.438399') AND ("flights"."takeoff_time" < '2010-03-07 15:54:05.438400')

.. ranges produce this:

Flight.where(:takeoff_time => Time::now..Time::now).count PGError: ERROR: syntax error at or near "16"
LINE 1: ... ("flights"."takeoff_time" BETWEEN 2010-03-07 16:53:53 +...

                                                         ^

: SELECT COUNT(*) AS count_id FROM "flights" WHERE ("flights"."takeoff_time" BETWEEN 2010-03-07 16:53:53 +0100 AND 2010-03-07 16:53:53 +0100)

Reported by Daniele Orlandi · March 7th, 2010 @ 03:30 PM

State: resolved
Milestone: 3.0.2
Assigned to: Pratik Pratik
Importance: Medium

Activity

  1. Santiago Pastorino
    Santiago Pastorino

    Can you provide a patch? or a the failing test?

    March 7th, 2010 @ 11:13 PM

  2. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open
    • Milestone cleared.

    March 7th, 2010 @ 11:13 PM

  3. Jeremy Kemper
    Jeremy Kemper
    • Assigned user set to Pratik

    March 7th, 2010 @ 11:27 PM

  4. Santiago Pastorino
  5. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to verified
    • Tag changed from activerecord 3.0, activerecord, postgresql, rails3, range to activerecord 3.0, activerecord, patch, postgresql, rails3, range

    March 8th, 2010 @ 03:23 AM

  6. Jeremy Kemper
    Jeremy Kemper
    • State changed from verified to resolved

    Upstream issue, resolving.

    March 8th, 2010 @ 04:48 AM

  7. Emilio Tagua
    Emilio Tagua

    Santiago this issue is already fixed in brynary/arel:

    http://github.com/brynary/arel/commit/e74bbd6830f5ca5f0ab1fe9f2f645...

    You should fork this repository since now is the official one for maintenance.

    March 8th, 2010 @ 12:29 PM

  8. Emilio Tagua
    Emilio Tagua

    Santiago this issue is already fixed in brynary/arel:

    http://github.com/brynary/arel/commit/e74bbd6830f5ca5f0ab1fe9f2f645...

    You should fork this repository since now is the official one for maintenance.

    March 8th, 2010 @ 12:30 PM

  9. Santiago Pastorino
    Santiago Pastorino

    Ok thanks, maybe a link from nkallen's arel to brynary could help.
    The exercise of redoing that things was very nice anyways.

    Why you don't release a fixed version of arel? it's an important thing, i think.

    March 8th, 2010 @ 01:18 PM

  10. Jeremy Kemper
    Jeremy Kemper
    • Milestone set to 3.0.2
    • Importance changed from to Medium

    October 15th, 2010 @ 11:01 PM