2011-03-30 27 views
2

我使用Heroku上開發的應用程序,但他們沒有加載的Postgres的PLPGSQL語言,這是造成試圖運行時,以下問題:我該如何重寫標準sql中的這個pgplsql函數?

CREATE FUNCTION profiles_search_trigger() RETURNS trigger AS $$ 
    begin 
    new.search_vector := 
     setweight(to_tsvector('pg_catalog.english', coalesce(new.display_name,'')), 'A') || 
     setweight(to_tsvector('pg_catalog.english', coalesce(new.about,'')), 'B') || 
     setweight(to_tsvector('pg_catalog.english', coalesce(new.music_education,'')), 'D') || 
     setweight(to_tsvector('pg_catalog.english', coalesce(new.other_experience,'')), 'D') || 
     setweight(to_tsvector('pg_catalog.english', coalesce(new.favourite_artists,'')), 'D'); 
    return new; 
    end 
    $$ LANGUAGE plpgsql; 

我怎麼能改寫這個使用標準的SQL,而比plpgsql?

回答

4

docs

這是目前不可能寫在普通的SQL函數語言中的觸發功能。

+0

啊,我錯過了。謝謝。我沒有看到任何文檔中提到的觸發器沒有使用觸發器函數,所以我猜我必須訴諸同等對待所有列 – 2011-03-30 13:16:35

+0

@Kevin:你可以創建一個表達式的索引而不會實現它,但是,你將不得不在查詢中重新輸入表達式:'CREATE INDEX ix_profiles_search ON配置文件USING GIST((setweight(...)|| ... || setweight(...)))'' – Quassnoi 2011-03-30 13:17:55