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 2.3.8 bug on find with include, order, limit and coalesce

#6548
  def test_finder_with_include_coalesce_order_by_and_limit
    query = "SELECT DISTINCT accounts.firm_name FROM accounts WHERE accounts.firm_id = 1"
    assert_nothing_raised { 
      Developer.all(:order => "COALESCE(developers.id, developers.salary)",
                    :conditions => "developers.name IN (#{query})",
                    :include => :audit_logs, 
                    :limit => 100) }
  end

Exception raised:
Class: <ActiveRecord::StatementInvalid>
Message: <"PGError: ERROR:  syntax error at or near \"AS\"\nLINE 1: ...pers\".id) \"developers\".id, COALESCE(developers.id AS alias_0...\n^\n: 
SELECT * FROM (SELECT DISTINCT ON (\"developers\".id) \"developers\".id, COALESCE(developers.id AS alias_0, developers.salary) AS alias_1 FROM \"developers\" WHERE (developers.name IN (SELECT DISTINCT accounts.firm_name FROM accounts WHERE accounts.firm_id = 1)) ) AS id_list ORDER BY id_list.alias_0 , id_list.alias_1  LIMIT 100">

Got it on activerecord-2.3.8. No other versions were tested.

Reported by Dmitry Novotochinov · March 9th, 2011 @ 12:54 PM

State: new
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Dmitry Novotochinov
  2. Vijay Dev
    Vijay Dev

    I guess the 2.3 branch is frozen except for security fixes.

    March 14th, 2011 @ 12:27 PM

  3. Dmitry Novotochinov
    Dmitry Novotochinov

    Oh, really? Didn't know that.

    March 14th, 2011 @ 12:31 PM