Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix #7200. Backport #5168 to 3-2-stable #7232

Merged
merged 1 commit into from

2 participants

@kennyj
Collaborator

Please see #7200 (postgresql_adapter.rb ignores NULLS while creating distincts in 3.2.7).

@carlosantoniodasilva

Looks good. Can you expand the commit message a little bit explaining the issue/fix (keeping the backport thing as part of the desc.)? Thanks @kennyj.

@kennyj kennyj Backport #5168 to 3-2-stable. Fix a problem that NULLS is ignored by …
…postgresql_adapter.rb while creating distincts.
f137c2b
@kennyj
Collaborator

Thanks @carlosantoniodasilva for commenting.
I updated this commit. how about it ?

@carlosantoniodasilva

I think it looks good yeah. Thanks.

@carlosantoniodasilva carlosantoniodasilva merged commit 59c4b22 into rails:3-2-stable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 2, 2012
  1. @kennyj

    Backport #5168 to 3-2-stable. Fix a problem that NULLS is ignored by …

    kennyj authored
    …postgresql_adapter.rb while creating distincts.
This page is out of date. Refresh to see the latest.
View
2  activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -1108,7 +1108,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
@@ -179,6 +179,11 @@ def test_substitute_at
assert_equal Arel.sql('$2'), bind
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|
Something went wrong with that request. Please try again.