Created
September 25, 2012 16:08
-
-
Save ziemekwolski/3782821 to your computer and use it in GitHub Desktop.
Does update match trigger?
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
PostgreSQL 9.1.4 on x86_64-apple-darwin11.3.1, compiled by Apple clang version 3.1 (tags/Apple/clang-318.0.61) (based on LLVM 3.1svn), 64-bit | |
ALTER TABLE users ADD COLUMN tsv tsvector; | |
UPDATE users SET tsv = (to_tsvector('english', coalesce("users"."email"::text, '')) || | |
to_tsvector('english', coalesce("users"."username"::text, '')) || | |
to_tsvector('english', coalesce("users"."first_name"::text, '')) || | |
to_tsvector('english', coalesce("users"."last_name"::text, ''))); | |
(is this trigger the same as the update above, or do I need my own function?) | |
CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE | |
ON users FOR EACH ROW EXECUTE PROCEDURE | |
tsvector_update_trigger(tsv, 'pg_catalog.english', email, username, first_name, last_name); | |
Users table: | |
Column | Type | Modifiers | |
------------------+-----------------------------+---------------------------------------------------- | |
id | integer | not null default nextval('users_id_seq'::regclass) | |
first_name | character varying(255) | | |
last_name | character varying(255) | | |
email | character varying(255) | | |
username | character varying(255) | | |
tsv | tsvector | | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment