2012-05-25 32 views
12

我想在Heroku上的新Postgres 9共享數據庫中使用contrib模塊。更具體而言,pg_trgmfuzzystrmatch模塊。在documentation它說如何在Heroku Postgres數據庫上啓用contrib模塊

此外,許多免費的附加功能適用,如 fuzzystrmatch,pg_trgm和unaccent。

我似乎無法找到如何真正實現共享Heroku的數據庫上這些模塊的任何文件。 請參閱下面的答案。

注:

我試圖連接到數據庫

heroku pg:psql HEROKU_POSTGRESQL_BROWN 

和運行

create extension pg_trgm 
create extension fuzzystrmatch 

加入他們,但試圖與使用它後

SELECT levenshtein('tests', 'test'); 

它仍然說

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. 

有人知道爲什麼會這樣?

回答

16

找到答案here同時淘洗堆棧溢出。不知道爲什麼它沒有出現在我的任何Google搜索中。如果其他人使用相同的措辭來搜索此問題,請在此留下問題。

要啓用模塊,你需要將它們添加到遷移如下:

def up 
    execute "create extension fuzzystrmatch" 
    execute "create extension pg_trgm" 
end 
+2

注意:您必須在postgresql 9.1上才能正常工作。要從舊版本升級,請執行以下操作:dev(https://gist.github.com/2883249),prod(https://devcenter.heroku.com/articles/upgrading-postgres-versions) – jfeust

+2

您可以獲得帶有'echo'的Heroku Postgres上可用擴展的完整列表顯示extwlist.extensions'| heroku pg:psql' https://devcenter.heroku.com/articles/heroku-postgres-extensions-postgis-full-text-search – GregB

7

在Rails的新版本中,它應該足以做到:

def change 
    enable_extension "fuzzystrmatch" 
    enable_extension "pg_trgm" 
end 

如果你需要寫updown方法,與enable_extension對應的方法是disable_extension

相關問題