Skip to content
Browse files

Merge pull request #5168 from kennyj/fix_5152

[PostgreSQL] Remove NULLS FIRST/LAST. Closes #5152
  • Loading branch information...
2 parents a19dd29 + 404b73b commit 699e460be2ae9ab419ff5ce17f7ebbbd63b4ef47 @tenderlove tenderlove committed Feb 27, 2012
View
2 activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -1189,7 +1189,7 @@ def distinct(columns, orders) #:nodoc:
# Construct a clean list of column names from the ORDER BY clause, removing
# any ASC/DESC modifiers
- order_columns = orders.collect { |s| s.gsub(/\s+(ASC|DESC)\s*/i, '') }
+ order_columns = orders.collect { |s| s.gsub(/\s+(ASC|DESC)\s*(NULLS\s+(FIRST|LAST)\s*)?/i, '') }
order_columns.delete_if { |c| c.blank? }
order_columns = order_columns.zip((0...order_columns.size).to_a).map { |s,i| "#{s} AS alias_#{i}" }
View
5 activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb
@@ -185,6 +185,11 @@ def test_partial_index
assert_equal "(number > 100)", index.where
end
+ def test_distinct_with_nulls
+ assert_equal "DISTINCT posts.title, posts.updater_id AS alias_0", @connection.distinct("posts.title", ["posts.updater_id desc nulls first"])
+ assert_equal "DISTINCT posts.title, posts.updater_id AS alias_0", @connection.distinct("posts.title", ["posts.updater_id desc nulls last"])
+ end
+
private
def insert(ctx, data)
binds = data.map { |name, value|

0 comments on commit 699e460

Please sign in to comment.
Something went wrong with that request. Please try again.