Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

simple detect functional index #26

Open
wants to merge 1 commit into from

2 participants

Ermolaev Andrey Vladimir Kochnev
Ermolaev Andrey

I want to create the following index

add_index :products, '(price_usual-price_retail)'

and have this error

PG::Error: ERROR:  column "(price_usual-price_retail)" does not exist

I think, detected a functional index should be easier

def quoted_columns_for_index(column_names, options = {})
    column_names.map do |name|
      if name.to_s.include?('(')
        name
      else
        quote_column_name(name)
      end
    end
end
Vladimir Kochnev

I think, we need to change api to something like:

add_index :comments, "lower(#{quote_column_name 'text'})"
add_index :products, functional: "#{quote_column_name 'price_usual'} - #{quote_column_name 'price_retail'}"

Detecting functional expressions is not a good idea anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 5, 2013
  1. simple detect functional index

    ermolaev authored
This page is out of date. Refresh to see the latest.
4 lib/core_ext/active_record/connection_adapters/abstract/schema_statements.rb
View
@@ -148,8 +148,8 @@ def add_index_options(table_name, column_name, options = {})
# Override super method to provide support for expression column names
def quoted_columns_for_index(column_names, options = {})
column_names.map do |name|
- if name =~ FUNCTIONAL_INDEX_REGEXP
- "#{$1}(#{quote_column_name($2)})"
+ if name.to_s.include?('(')
+ name
else
quote_column_name(name)
end
Something went wrong with that request. Please try again.