aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
diff options
context:
space:
mode:
authorRick Olson <technoweenie@gmail.com>2006-10-13 08:29:00 +0000
committerRick Olson <technoweenie@gmail.com>2006-10-13 08:29:00 +0000
commite789b26e652d9f0ee6ca538615b8d570cb4c91b5 (patch)
treed9c53e9f1668ecf144ebe23d8388c58d6549c8a5 /activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
parentce1d14430f3ff5c8743541ce5f10b71a083f9c90 (diff)
downloadrails-e789b26e652d9f0ee6ca538615b8d570cb4c91b5.tar.gz
rails-e789b26e652d9f0ee6ca538615b8d570cb4c91b5.tar.bz2
rails-e789b26e652d9f0ee6ca538615b8d570cb4c91b5.zip
fix select_limited_ids_list issues in postgresql, retain current behavior in other adapters [Rick]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5291 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb11
1 files changed, 10 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
index a2eaac549e..975768a758 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
@@ -186,7 +186,6 @@ module ActiveRecord
execute "ROLLBACK"
end
-
# SCHEMA STATEMENTS ========================================
# Return the list of all tables in the schema search path.
@@ -384,6 +383,16 @@ module ActiveRecord
'bigint'
end
end
+
+ # PostgreSQL requires the ORDER BY columns in the select list for distinct queries.
+ # If you select distinct by a column though, you must pass that column in the order by clause too:
+ #
+ # distinct("posts.id", 'posts.id', 'posts.created_at')
+ def distinct(columns, *order_columns)
+ order_columns.delete_if &:blank?
+ sql = "DISTINCT ON (#{columns}) #{columns}"
+ sql << (order_columns.any? ? ", #{order_columns * ', '}" : '')
+ end
private
BYTEA_COLUMN_TYPE_OID = 17