1 CREATE OR REPLACE FUNCTION public.create_plpgsql_language ()
4 CREATE LANGUAGE plpgsql;
5 SELECT 'language plpgsql created'::TEXT;
12 WHERE lanname='plpgsql')
14 (SELECT 'language already installed'::TEXT)
16 (SELECT public.create_plpgsql_language())
19 DROP FUNCTION public.create_plpgsql_language ();
21 CREATE OR REPLACE FUNCTION set_question_tsv() RETURNS TRIGGER AS $$
24 setweight(to_tsvector('english', coalesce(new.tagnames,'')), 'A') ||
25 setweight(to_tsvector('english', coalesce(new.title,'')), 'B') ||
26 setweight(to_tsvector('english', coalesce(new.html,'')), 'C');
31 CREATE OR REPLACE FUNCTION public.create_tsv_question_column ()
34 ALTER TABLE question ADD COLUMN tsv tsvector;
36 CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE
37 ON question FOR EACH ROW EXECUTE PROCEDURE set_question_tsv();
39 CREATE INDEX question_tsv ON question USING gin(tsv);
41 SELECT 'tsv column created'::TEXT;
46 (SELECT true::BOOLEAN FROM pg_attribute WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'question') AND attname = 'tsv')
48 (SELECT 'Tsv column already exists'::TEXT)
50 (SELECT public.create_tsv_question_column())
54 DROP FUNCTION public.create_tsv_question_column ();