Re: FTS trigger works 1 at a time, but fails with bulk insert script

From: Malik Rumi <malik(dot)a(dot)rumi(at)gmail(dot)com>
To: adrian(dot)klaver(at)aklaver(dot)com
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: FTS trigger works 1 at a time, but fails with bulk insert script
Date: 2018-10-08 19:29:47
Message-ID: CAKd6oByX51Y4EzHKVdLESxViLssiqvK6HZvN8rK=31ksptTg6Q@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

1. This code is entry_search_vector_trigger(), one of 3 trigger functions
based on the Django model that created the site.
2. So this is the trigger definition (as far as I know) and it is on the
Entry table. There is also a Tag table and the Tags intersection table.
3. Uhh, I'm not sure. I assume this is it, that when a new entry is posted,
the function that parses the entry into searchable text and indexes the
words is called. But I can tell you I got this code from this blog post:
blog.lotech.org/postgres-full-text-search-with-django.html. I asked the
author about this issue. He said he wasn't sure wthout debugging if it was
something he left out or something I did wrong.
4. Postgresql 9.4. Yea, I know, I should upgrade...

*“None of you has faith until he loves for his brother or his neighbor what
he loves for himself.”*

On Tue, Oct 2, 2018 at 6:27 PM Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
wrote:

> On 10/2/18 10:34 AM, Malik Rumi wrote:
> > I have set up Postgres FTS on a Django/Python web site, and it works as
> > expected except for this one thing. When I wrote a script to bulk insert
> > legacy docs, the script works fine but the FTS trigger does not fire. I
> > have to go back and open each document one at a time to get them indexed.
> >
> > What am I missing to make this work? Thanks.
>
> Have no idea as there is not enough information.
>
> To begin with:
>
> 1) What is code below?
>
> 2) What is the trigger definition and on what table?
>
> 3) What is the function the trigger is calling?
>
> 4) For good measure what version of Postgres?
>
> >
> > BEGIN
> > SELECT setweight(to_tsvector(NEW.title), 'A') ||
> > setweight(to_tsvector(NEW.content), 'B') ||
> > setweight(to_tsvector(NEW.category), 'D') ||
> > setweight(to_tsvector(COALESCE(string_agg(tag.tag,
> > ', '), '')), 'C')
> > INTO NEW.search_vector
> > FROM ktab_entry AS entry
> > LEFT JOIN ktab_entry_tags AS entry_tags ON
> > entry_tags.entry_id = entry.id <http://entry.id>
> > LEFT JOIN ktab_tag AS tag ON tag.id <http://tag.id> =
> > entry_tags.tag_id
> > WHERE entry.id <http://entry.id> = NEW.id
> > GROUP BY entry.id <http://entry.id>, category;
> > RETURN NEW;
> > END;
> >
> >
> > */“None of you has faith until he loves for his brother or his neighbor
> > what he loves for himself.”/*
>
>
> --
> Adrian Klaver
> adrian(dot)klaver(at)aklaver(dot)com
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2018-10-08 19:56:58 Re: FTS trigger works 1 at a time, but fails with bulk insert script
Previous Message ROS Didier 2018-10-08 15:32:45 RE: Why the index is not used ?