This project is archived and is in readonly mode.

#6548 new
Dmitry Novotochinov

ActiveRecord 2.3.8 bug on find with include, order, limit and coalesce

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

  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.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages