Merge "Prevent revisions with rev_page = 0 from being inserted into the DB"
[lhc/web/wiklou.git] / maintenance / postgres / archives / patch-tsearch2funcs.sql
1 -- Should be run on Postgres 8.3 or newer to remove the 'default'
2
3 CREATE OR REPLACE FUNCTION ts2_page_title()
4 RETURNS TRIGGER
5 LANGUAGE plpgsql AS
6 $mw$
7 BEGIN
8 IF TG_OP = 'INSERT' THEN
9 NEW.titlevector = to_tsvector(REPLACE(NEW.page_title,'/',' '));
10 ELSIF NEW.page_title != OLD.page_title THEN
11 NEW.titlevector := to_tsvector(REPLACE(NEW.page_title,'/',' '));
12 END IF;
13 RETURN NEW;
14 END;
15 $mw$;
16
17 CREATE OR REPLACE FUNCTION ts2_page_text()
18 RETURNS TRIGGER
19 LANGUAGE plpgsql AS
20 $mw$
21 BEGIN
22 IF TG_OP = 'INSERT' THEN
23 NEW.textvector = to_tsvector(NEW.old_text);
24 ELSIF NEW.old_text != OLD.old_text THEN
25 NEW.textvector := to_tsvector(NEW.old_text);
26 END IF;
27 RETURN NEW;
28 END;
29 $mw$;