Skip to content

Instantly share code, notes, and snippets.

@ojacobson
Last active December 21, 2015 21:29
Show Gist options
  • Save ojacobson/6369022 to your computer and use it in GitHub Desktop.
Save ojacobson/6369022 to your computer and use it in GitHub Desktop.
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