From 4287f6d456518652bb1a2035c9ecf96f1be28f79 Mon Sep 17 00:00:00 2001 From: Godfrey Chan Date: Sat, 23 Aug 2014 23:54:22 -0700 Subject: [PATCH] CHANGELOG & improvements to #16649 * Require either FIRST or LAST qualifier for "NULLS ..." * Require whitespace before "NULLS ..." --- activerecord/CHANGELOG.md | 7 +++++++ .../connection_adapters/postgresql/schema_statements.rb | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index c2e79e9f02..356911d340 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,10 @@ +* Fixed a regression where whitespaces were stripped from DISTINCT queries in + PostgreSQL. + + *Agis Anastasopoulos* + + Fixes #16623. + * Fix has_many :through relation merging failing when dynamic conditions are passed as a lambda with an arity of one. diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb index 6d5270cfc6..323da7b717 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb @@ -549,8 +549,8 @@ def columns_for_distinct(columns, orders) #:nodoc: # Convert Arel node to string s = s.to_sql unless s.is_a?(String) # Remove any ASC/DESC modifiers - s.gsub(/\s+(?:ASC|DESC)\s*/i, '') - .gsub(/\s*NULLS\s+(?:FIRST|LAST)?\s*/i, '') + s.gsub(/\s+(?:ASC|DESC)\b/i, '') + .gsub(/\s+NULLS\s+(?:FIRST|LAST)\b/i, '') }.reject(&:blank?).map.with_index { |column, i| "#{column} AS alias_#{i}" } [super, *order_columns].join(', ')