Created
July 23, 2011 18:25
-
-
Save ruckus/1101717 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CREATE FUNCTION albums_vector_update() RETURNS TRIGGER AS $$ | |
| BEGIN | |
| IF TG_OP = 'INSERT' THEN | |
| new.search_vector = to_tsvector('pg_catalog.english', COALESCE(NEW.title, '')); | |
| END IF; | |
| IF TG_OP = 'UPDATE' THEN | |
| IF NEW.title <> OLD.title THEN | |
| new.search_vector = to_tsvector('pg_catalog.english', COALESCE(NEW.title, '')); | |
| END IF; | |
| END IF; | |
| RETURN NEW; | |
| END | |
| $$ LANGUAGE 'plpgsql'; | |
| CREATE TRIGGER tsvectorupdate AFTER INSERT OR UPDATE ON albums | |
| FOR EACH ROW EXECUTE PROCEDURE albums_vector_update(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment