Skip to content

Instantly share code, notes, and snippets.

@ruckus
Created July 23, 2011 18:25
Show Gist options
  • Select an option

  • Save ruckus/1101717 to your computer and use it in GitHub Desktop.

Select an option

Save ruckus/1101717 to your computer and use it in GitHub Desktop.
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