I'm trying to use contrib modules in the new Postgres 9 shared databases on Heroku. More specifically, the pg_trgm and fuzzystrmatch modules. In the documentation it says
In addition, many complimentary extensions are available such as fuzzystrmatch, pg_trgm, and unaccent.
I can't seem to find any documentation on HOW to actually enable these modules on a shared Heroku database. See answer below.
NOTE:
I tried adding them by connecting to the database with
heroku pg:psql HEROKU_POSTGRESQL_BROWN
and running
create extension pg_trgm
create extension fuzzystrmatch
but after trying to use it with
SELECT levenshtein('tests', 'test');
it still said
ERROR: function levenshtein(unknown, unknown) does not existLINE 1: SELECT levenshtein('tests', 'test');
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
Anybody know why this happens?
Found answer here while scouring Stack Overflow. Don't know why it didn't come up in any of my Google searches. Going to leave the question here if anybody else uses the same wording to search for this.
To enable modules, you need to add them to a migration as follows:
def up
execute "create extension fuzzystrmatch"
execute "create extension pg_trgm"
end
In newer versions of Rails it should be sufficient to do:
def change
enable_extension "fuzzystrmatch"
enable_extension "pg_trgm"
end
If you need to write up
and down
methods, the corresponding method to enable_extension
is disable_extension
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With