2

Trying to implement the suggestions made to this other question:

question related

I have written this migration to remove the current index and create the new one:

class ChangeIndexes < ActiveRecord::Migration[5.1]
  def change
    remove_index :part_masters, name: "part_masters_on_combo_idx" 

    execute <<-SQL
      CREATE INDEX ON part_masters (lower(unaccent(combo)) text_pattern_ops);
      CREATE INDEX ON locations (lower(unaccent(ubicacion)) text_pattern_ops);     
    SQL
   end
end

The problem is that I'm getting this error, I think because I'm using functions like lower or unaccent to create the index:

PG::InvalidObjectDefinition: ERROR: functions in index expression must be marked IMMUTABLE

1 Answer 1

2

In case someone finds it useful in the future, the user @laurenz-albe provided the solution for this question in the referenced question, just had to create the function unaccent as a custom pg function:

CREATE FUNCTION my_unaccent(text) RETURNS text LANGUAGE SQL IMMUTABLE AS 
'SELECT unaccent($1)';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.