create extension tsvector2; SELECT strip('w:12B w:13* w:12,5,6 a:1,3* a:3 w asd:1dc asd'::tsvector2); strip --------------- 'a' 'asd' 'w' (1 row) SELECT strip('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3'::tsvector2); strip ---------------------------------------------- 'base' 'hidden' 'rebel' 'spaceship' 'strike' (1 row) SELECT strip('base hidden rebel spaceship strike'::tsvector2); strip ---------------------------------------------- 'base' 'hidden' 'rebel' 'spaceship' 'strike' (1 row) SELECT ts_delete(to_tsvector2('english', 'Rebel spaceships, striking from a hidden base'), 'spaceship'); ts_delete ------------------------------------------ 'base':7 'hidden':6 'rebel':1 'strike':3 (1 row) SELECT ts_delete('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3'::tsvector2, 'base'); ts_delete -------------------------------------------------------------- 'hidden':6 'rebel':1 'spaceship':2,33A,34B,35C,36 'strike':3 (1 row) SELECT ts_delete('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3'::tsvector2, 'bas'); ts_delete ----------------------------------------------------------------------- 'base':7 'hidden':6 'rebel':1 'spaceship':2,33A,34B,35C,36 'strike':3 (1 row) SELECT ts_delete('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3'::tsvector2, 'bases'); ts_delete ----------------------------------------------------------------------- 'base':7 'hidden':6 'rebel':1 'spaceship':2,33A,34B,35C,36 'strike':3 (1 row) SELECT ts_delete('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3'::tsvector2, 'spaceship'); ts_delete ------------------------------------------ 'base':7 'hidden':6 'rebel':1 'strike':3 (1 row) SELECT ts_delete('base hidden rebel spaceship strike'::tsvector2, 'spaceship'); ts_delete ---------------------------------- 'base' 'hidden' 'rebel' 'strike' (1 row) SELECT ts_delete('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3'::tsvector2, ARRAY['spaceship','rebel']); ts_delete -------------------------------- 'base':7 'hidden':6 'strike':3 (1 row) SELECT ts_delete('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3'::tsvector2, ARRAY['spaceships','rebel']); ts_delete ------------------------------------------------------------- 'base':7 'hidden':6 'spaceship':2,33A,34B,35C,36 'strike':3 (1 row) SELECT ts_delete('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3'::tsvector2, ARRAY['spaceshi','rebel']); ts_delete ------------------------------------------------------------- 'base':7 'hidden':6 'spaceship':2,33A,34B,35C,36 'strike':3 (1 row) SELECT ts_delete('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3'::tsvector2, ARRAY['spaceship','leya','rebel']); ts_delete -------------------------------- 'base':7 'hidden':6 'strike':3 (1 row) SELECT ts_delete('base hidden rebel spaceship strike'::tsvector2, ARRAY['spaceship','leya','rebel']); ts_delete -------------------------- 'base' 'hidden' 'strike' (1 row) SELECT ts_delete('base hidden rebel spaceship strike'::tsvector2, ARRAY['spaceship','leya','rebel','rebel']); ts_delete -------------------------- 'base' 'hidden' 'strike' (1 row) SELECT ts_delete('base hidden rebel spaceship strike'::tsvector2, ARRAY['spaceship','leya','rebel', NULL]); ERROR: lexeme array may not contain nulls SELECT unnest('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3'::tsvector2); unnest --------------------------------------------- (base,{7},{D}) (hidden,{6},{D}) (rebel,{1},{D}) (spaceship,"{2,33,34,35,36}","{D,A,B,C,D}") (strike,{3},{D}) (5 rows) SELECT unnest('base hidden rebel spaceship strike'::tsvector2); unnest --------------- (base,,) (hidden,,) (rebel,,) (spaceship,,) (strike,,) (5 rows) SELECT * FROM unnest('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3'::tsvector2); lexeme | positions | weights -----------+-----------------+------------- base | {7} | {D} hidden | {6} | {D} rebel | {1} | {D} spaceship | {2,33,34,35,36} | {D,A,B,C,D} strike | {3} | {D} (5 rows) SELECT * FROM unnest('base hidden rebel spaceship strike'::tsvector2); lexeme | positions | weights -----------+-----------+--------- base | | hidden | | rebel | | spaceship | | strike | | (5 rows) SELECT lexeme, positions[1] from unnest('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3'::tsvector2); lexeme | positions -----------+----------- base | 7 hidden | 6 rebel | 1 spaceship | 2 strike | 3 (5 rows) SELECT tsvector2_to_array('base:7 hidden:6 rebel:1 spaceship:2,33A,34B,35C,36D strike:3'::tsvector2); tsvector2_to_array -------------------------------------- {base,hidden,rebel,spaceship,strike} (1 row) SELECT tsvector2_to_array('base hidden rebel spaceship strike'::tsvector2); tsvector2_to_array -------------------------------------- {base,hidden,rebel,spaceship,strike} (1 row) SELECT array_to_tsvector2(ARRAY['base','hidden','rebel','spaceship','strike']); array_to_tsvector2 ---------------------------------------------- 'base' 'hidden' 'rebel' 'spaceship' 'strike' (1 row) SELECT array_to_tsvector2(ARRAY['base','hidden','rebel','spaceship', NULL]); ERROR: lexeme array may not contain nulls -- array_to_tsvector2 must sort and de-dup SELECT array_to_tsvector2(ARRAY['foo','bar','baz','bar']); array_to_tsvector2 -------------------- 'bar' 'baz' 'foo' (1 row) SELECT setweight('w:12B w:13* w:12,5,6 a:1,3* a:3 w asd:1dc asd zxc:81,567,222A'::tsvector2, 'c'); setweight ---------------------------------------------------------- 'a':1C,3C 'asd':1C 'w':5C,6C,12C,13C 'zxc':81C,222C,567C (1 row) SELECT setweight('a:1,3A asd:1C w:5,6,12B,13A zxc:81,222A,567'::tsvector2, 'c'); setweight ---------------------------------------------------------- 'a':1C,3C 'asd':1C 'w':5C,6C,12C,13C 'zxc':81C,222C,567C (1 row) SELECT setweight('a:1,3A asd:1C w:5,6,12B,13A zxc:81,222A,567'::tsvector2, 'c', '{a}'); setweight ------------------------------------------------------ 'a':1C,3C 'asd':1C 'w':5,6,12B,13A 'zxc':81,222A,567 (1 row) SELECT setweight('a:1,3A asd:1C w:5,6,12B,13A zxc:81,222A,567'::tsvector2, 'c', '{a}'); setweight ------------------------------------------------------ 'a':1C,3C 'asd':1C 'w':5,6,12B,13A 'zxc':81,222A,567 (1 row) SELECT setweight('a:1,3A asd:1C w:5,6,12B,13A zxc:81,222A,567'::tsvector2, 'c', '{a,zxc}'); setweight -------------------------------------------------------- 'a':1C,3C 'asd':1C 'w':5,6,12B,13A 'zxc':81C,222C,567C (1 row) SELECT setweight('a asd w:5,6,12B,13A zxc'::tsvector2, 'c', '{a,zxc}'); setweight --------------------------------- 'a' 'asd' 'w':5,6,12B,13A 'zxc' (1 row) SELECT setweight('a asd w:5,6,12B,13A zxc'::tsvector2, 'c', ARRAY['a', 'zxc', NULL]); ERROR: lexeme array may not contain nulls SELECT ts_filter('base:7A empir:17 evil:15 first:11 galact:16 hidden:6A rebel:1A spaceship:2A strike:3A victori:12 won:9'::tsvector2, '{a}'); ts_filter ------------------------------------------------------------- 'base':7A 'hidden':6A 'rebel':1A 'spaceship':2A 'strike':3A (1 row) SELECT ts_filter('base hidden rebel spaceship strike'::tsvector2, '{a}'); ts_filter ----------- (1 row) SELECT ts_filter('base hidden rebel spaceship strike'::tsvector2, '{a,b,NULL}'); ERROR: weight array may not contain nulls CREATE TABLE t1(a tsvector2, t text); CREATE TRIGGER tsvectorupdate BEFORE UPDATE OR INSERT ON t1 FOR EACH ROW EXECUTE PROCEDURE tsvector2_update_trigger(a, 'pg_catalog.english', t); SELECT * FROM t1; a | t ---+--- (0 rows) INSERT INTO t1 (t) VALUES ('345 qwerty'); SELECT * FROM t1; a | t --------------------+------------ '345':1 'qwerti':2 | 345 qwerty (1 row) UPDATE t1 SET t = null WHERE t = '345 qwerty'; SELECT * FROM t1; a | t ---+--- | (1 row) INSERT INTO t1 (t) VALUES ('345 qwerty'); SELECT * FROM t1; a | t --------------------+------------ | '345':1 'qwerti':2 | 345 qwerty (2 rows) DROP TABLE t1 CASCADE; CREATE TABLE t2(a tsvector2, t text, c regconfig); CREATE TRIGGER tsvectorupdate BEFORE UPDATE OR INSERT ON t2 FOR EACH ROW EXECUTE PROCEDURE tsvector2_update_trigger_column(a, c, t); SELECT * FROM t2; a | t | c ---+---+--- (0 rows) INSERT INTO t2 (t, c) VALUES ('345 qwerty', 'pg_catalog.english'); SELECT * FROM t2; a | t | c --------------------+------------+--------- '345':1 'qwerti':2 | 345 qwerty | english (1 row) UPDATE t2 SET t = null WHERE t = '345 qwerty'; SELECT * FROM t2; a | t | c ---+---+--------- | | english (1 row) INSERT INTO t2 (t, c) VALUES ('345 qwerty', 'pg_catalog.english'); SELECT * FROM t2; a | t | c --------------------+------------+--------- | | english '345':1 'qwerti':2 | 345 qwerty | english (2 rows) DROP TABLE t2 CASCADE; drop extension tsvector2 cascade;