Skip to content

Commit

Permalink
Using PostgreSQL's array_agg function if it exists (v8.4 or newer).
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Sep 2, 2011
1 parent 780fb80 commit 14cee4c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions HISTORY
@@ -1,4 +1,5 @@
Edge:
* Use PostgreSQL's array_agg function if it exists, instead of array_accum (PG v8.4 or newer).
* Shuffle multiple Sphinx addresses by default, but allow that to be turned off (Ngan Pham).
* Fix string attributes when using Sphinx 2.0.1 and bin_path.

Expand Down
12 changes: 10 additions & 2 deletions lib/thinking_sphinx/adapters/postgresql_adapter.rb
Expand Up @@ -20,7 +20,11 @@ def concatenate(clause, separator = ' ')
end

def group_concatenate(clause, separator = ' ')
"array_to_string(array_accum(COALESCE(#{clause}, '0')), '#{separator}')"
if connection.raw_connection.server_version >= 80400
"array_to_string(array_agg(COALESCE(#{clause}, '0')), '#{separator}')"
else
"array_to_string(array_accum(COALESCE(#{clause}, '0')), '#{separator}')"
end
end

def cast_to_string(clause)
Expand Down Expand Up @@ -105,7 +109,11 @@ def execute_command(command, output_error = false)
end

def create_array_accum_function
if connection.raw_connection.respond_to?(:server_version) && connection.raw_connection.server_version > 80200
if connection.raw_connection.respond_to?(:server_version) &&
connection.raw_connection.server_version >= 80400
return
elsif connection.raw_connection.respond_to?(:server_version) &&
connection.raw_connection.server_version > 80200
execute <<-SQL
CREATE AGGREGATE array_accum (anyelement)
(
Expand Down

0 comments on commit 14cee4c

Please sign in to comment.