Last active
December 21, 2015 21:29
-
-
Save ojacobson/6369022 to your computer and use it in GitHub Desktop.
This file contains 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 table if not exists "Products_productindexwords" ( | |
word varchar primary key | |
); | |
do $do$ | |
begin | |
create temporary table words ( | |
tsv tsvector | |
) on commit drop; | |
insert into words | |
with strings(s) as ( | |
values | |
('title'), -- (NEW.title), | |
('description') -- (NEW.description) | |
) select | |
to_tsvector(string_agg(s, ' ')) as tsv | |
from | |
strings; | |
insert into "Products_productindexwords" (word) | |
select word from ts_stat($stat$ | |
select tsv from words | |
$stat$); | |
end; | |
$do$; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment