class ThinkingSphinx::PostgreSQLAdapter

Public Instance Methods

boolean(value) click to toggle source
# File lib/thinking_sphinx/adapters/postgresql_adapter.rb, line 65
def boolean(value)
  value ? 'TRUE' : 'FALSE'
end
cast_to_datetime(clause) click to toggle source
# File lib/thinking_sphinx/adapters/postgresql_adapter.rb, line 34
def cast_to_datetime(clause)
  if ThinkingSphinx::Configuration.instance.use_64_bit
    "cast(floor(extract(epoch from #{clause})) as bigint)"
  else
    "cast(floor(extract(epoch from #{clause})) as int)"
  end
end
cast_to_int(clause) click to toggle source
# File lib/thinking_sphinx/adapters/postgresql_adapter.rb, line 46
def cast_to_int(clause)
  "#{clause}::INT8"
end
cast_to_string(clause) click to toggle source
# File lib/thinking_sphinx/adapters/postgresql_adapter.rb, line 30
def cast_to_string(clause)
  clause
end
cast_to_unsigned(clause) click to toggle source
# File lib/thinking_sphinx/adapters/postgresql_adapter.rb, line 42
def cast_to_unsigned(clause)
  clause
end
concatenate(clause, separator = ' ') click to toggle source
# File lib/thinking_sphinx/adapters/postgresql_adapter.rb, line 12
def concatenate(clause, separator = ' ')
  if clause[%r^COALESCE/]
    clause.split('), ').join(") || '#{separator}' || ")
  else
    clause.split(', ').collect { |field|
      "CAST(COALESCE(#{field}::varchar, '') as varchar)"
    }.join(" || '#{separator}' || ")
  end
end
convert_nulls(clause, default = '') click to toggle source
# File lib/thinking_sphinx/adapters/postgresql_adapter.rb, line 50
def convert_nulls(clause, default = '')
  default = case default
  when String
    "'#{default}'"
  when NilClass
    'NULL'
  when Fixnum
    "#{default}::bigint"
  else
    default
  end

  "COALESCE(#{clause}, #{default})"
end
crc(clause, blank_to_null = false) click to toggle source
# File lib/thinking_sphinx/adapters/postgresql_adapter.rb, line 69
def crc(clause, blank_to_null = false)
  clause = "NULLIF(#{clause},'')" if blank_to_null
  "crc32(#{clause})"
end
group_concatenate(clause, separator = ' ') click to toggle source
# File lib/thinking_sphinx/adapters/postgresql_adapter.rb, line 22
def group_concatenate(clause, separator = ' ')
  if server_version >= 80400
    "array_to_string(array_agg(COALESCE(#{clause}, '0')), '#{separator}')"
  else
    "array_to_string(array_accum(COALESCE(#{clause}, '0')), '#{separator}')"
  end
end
setup() click to toggle source
# File lib/thinking_sphinx/adapters/postgresql_adapter.rb, line 3
def setup
  create_array_accum_function
  create_crc32_function
end
sphinx_identifier() click to toggle source
# File lib/thinking_sphinx/adapters/postgresql_adapter.rb, line 8
def sphinx_identifier
  "pgsql"
end
time_difference(diff) click to toggle source
# File lib/thinking_sphinx/adapters/postgresql_adapter.rb, line 78
def time_difference(diff)
  "current_timestamp - interval '#{diff} seconds'"
end
utc_query_pre() click to toggle source
# File lib/thinking_sphinx/adapters/postgresql_adapter.rb, line 82
def utc_query_pre
  "SET TIME ZONE 'UTC'"
end
utf8_query_pre() click to toggle source
# File lib/thinking_sphinx/adapters/postgresql_adapter.rb, line 74
def utf8_query_pre
  nil
end