Skip to content

Conversation

agis
Copy link
Contributor

@agis agis commented Aug 22, 2014

Fixes the regression described in #16623 present in 4.0.10rc1 & 4.1.6.rc1. It was introduced by 3d5a201.

@agis agis changed the title Add failing test case for #16623 Fix postgresql adapter #columns_for_distinct trimming whitespace it should not Aug 23, 2014
@agis agis changed the title Fix postgresql adapter #columns_for_distinct trimming whitespace it should not Fix postgresql adapter #columns_for_distinct trimming whitespace it shouldn't Aug 23, 2014
@agis
Copy link
Contributor Author

agis commented Aug 23, 2014

The travis failures are irrelevant with the PR.

@@ -549,7 +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*(?:NULLS\s+(?:FIRST|LAST)\s*)?/i, '')
s.gsub(/\s+(ASC|DESC)\s*/i, '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can keep the (?: on (?:ASC|DESC) - we don't use the capture

jeremy referenced this pull request Aug 23, 2014
Fixed #columns_for_distinct of postgresql adapter

Conflicts:
	activerecord/CHANGELOG.md

Conflicts:
	activerecord/CHANGELOG.md
@jeremy
Copy link
Member

jeremy commented Aug 24, 2014

Looking good. Ready for merge and backport.

@@ -549,7 +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*(?:NULLS\s+(?:FIRST|LAST)\s*)?/i, '')
s.gsub(/\s+(?:ASC|DESC)\s*/i, '')
.gsub(/\s*NULLS\s+(?:FIRST|LAST)?\s*/i, '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make (?:FIRST|LAST) optional?

Also, I don't like the fact that we don't require whitespace before NULLS. Can we just remove the trailing \s* from both expressions instead?

And let's end both with a \b, for similar reasons: we're looking for whole words here.

@chancancode chancancode merged commit 291fece into rails:master Aug 24, 2014
chancancode added a commit that referenced this pull request Aug 24, 2014
Fix postgresql adapter #columns_for_distinct trimming whitespace it shouldn't
chancancode added a commit that referenced this pull request Aug 24, 2014
* Require either FIRST or LAST qualifier for "NULLS ..."
* Require whitespace before "NULLS ..."
chancancode added a commit that referenced this pull request Aug 24, 2014
Fix postgresql adapter #columns_for_distinct trimming whitespace it shouldn't
chancancode added a commit that referenced this pull request Aug 24, 2014
* Require either FIRST or LAST qualifier for "NULLS ..."
* Require whitespace before "NULLS ..."
chancancode added a commit that referenced this pull request Aug 24, 2014
Fix postgresql adapter #columns_for_distinct trimming whitespace it shouldn't
chancancode added a commit that referenced this pull request Aug 24, 2014
* Require either FIRST or LAST qualifier for "NULLS ..."
* Require whitespace before "NULLS ..."

Conflicts:
	activerecord/CHANGELOG.md
chancancode added a commit that referenced this pull request Aug 24, 2014
Fix postgresql adapter #columns_for_distinct trimming whitespace it shouldn't

Conflicts:
	activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb
chancancode added a commit that referenced this pull request Aug 24, 2014
* Require either FIRST or LAST qualifier for "NULLS ..."
* Require whitespace before "NULLS ..."

Conflicts:
	activerecord/CHANGELOG.md
chancancode added a commit that referenced this pull request Aug 24, 2014
Fix postgresql adapter #columns_for_distinct trimming whitespace it shouldn't

Conflicts:
	activerecord/test/cases/adapters/postgresql/postgresql_adapter_test.rb
chancancode added a commit that referenced this pull request Aug 24, 2014
* Require either FIRST or LAST qualifier for "NULLS ..."
* Require whitespace before "NULLS ..."

Conflicts:
	activerecord/CHANGELOG.md

Conflicts:
	activerecord/CHANGELOG.md
@chancancode
Copy link
Member

Merged into master, 4-1-stable, 4-1-6, 4-0-stable, 4-0-10, along with a CHANGELOG entry and @matthewd's suggestions. Thank you all ❤️ 💚 💙 💛 💜

@chancancode
Copy link
Member

cc @rafaelfranca

@agis agis deleted the pg-columns-for-distinct branch August 24, 2014 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants