activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb
# Returns a SELECT DISTINCT clause for a given set of columns and a given ORDER BY clause.
#
# PostgreSQL requires the ORDER BY columns in the select list for distinct queries, and
# requires that the ORDER BY include the distinct column.
#
#   distinct("posts.id", ["posts.created_at desc"])
#   # => "DISTINCT posts.id, posts.created_at AS alias_0"
Returns a SELECT DISTINCT clause for a given set of columns and a given ORDER BY clause.
PostgreSQL requires the ORDER BY columns in the select list for distinct queries, and
requires that the ORDER BY include the distinct column.


Returns a SELECT DISTINCT clause for a given set of columns and a given ORDER BY clause . PostgreSQL requires the ORDER BY columns in the select list for distinct queries and requires that the ORDER BY include the distinct column .
def distinct(columns, orders) 
          order_columns = orders.map{ |s|
              s = s.to_sql unless s.is_a?(String)
              s.gsub(/\s+(ASC|DESC)\s*(NULLS\s+(FIRST|LAST)\s*)?/i, '')
            }.reject(&:blank?).map.with_index { |column, i| "#{column} AS alias_#{i}" }
          [super].concat(order_columns).join(', ')
        end
def distinct ( columns , orders ) order_columns = orders . map { | s | s = s . to_sql unless s . is_a? ( String ) s . gsub ( / \s +(ASC|DESC) \s *(NULLS \s +(FIRST|LAST) \s *)? /i , '' ) } . reject ( & :blank? ) . map . with_index { | column , i | "#{column} AS alias_#{i}" } [ super ] . concat ( order_columns ) . join ( ', ' ) end
Returns a SELECT DISTINCT clause for a given set of columns and a given ORDER BY clause.
Returns a SELECT DISTINCT clause for a given set of columns and a given ORDER BY clause .
#:nodoc: # Convert Arel node to string # Remove any ASC/DESC modifiers
columns
orders