Created
August 20, 2013 19:42
-
-
Save glittershark/6286217 to your computer and use it in GitHub Desktop.
Postgresql aggregate function for tsvectors
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
CREATE OR REPLACE FUNCTION concat_tsvectors(tsv1 tsvector, tsv2 tsvector) | |
RETURNS tsvector AS $$ | |
BEGIN | |
RETURN coalesce(tsv1, to_tsvector('default', '')) | |
|| coalesce(tsv2, to_tsvector('default', '')); | |
END; | |
$$ LANGUAGE plpgsql; | |
CREATE AGGREGATE tsvector_agg ( | |
BASETYPE = tsvector, | |
SFUNC = concat_tsvectors, | |
STYPE = tsvector, | |
INITCOND = '' | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A version using the built in
tsvector_concat
function as suggested by @EvanCarroll: