Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jQxdP-0004lx-Ds for pgsql-general@arkaria.postgresql.org; Tue, 21 Apr 2020 18:28:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jQxdO-0003UO-2y for pgsql-general@arkaria.postgresql.org; Tue, 21 Apr 2020 18:28:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jQxdN-0003UH-NG for pgsql-general@lists.postgresql.org; Tue, 21 Apr 2020 18:28:37 +0000 Received: from wout5-smtp.messagingengine.com ([64.147.123.21]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jQxdL-0008C0-6x for pgsql-general@lists.postgresql.org; Tue, 21 Apr 2020 18:28:36 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id ABD4262C; Tue, 21 Apr 2020 14:28:33 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Tue, 21 Apr 2020 14:28:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=U HZu0hr00LFyw79MEJKvUal7Ug1S1t8BwRdKFSyXE4U=; b=NFT0oS1drS+a1bCGG RaL8IzalB+qz8+oRMA1g8nbmZ+Hb7u4wQFe37hRXYp5xvIJ763BDtuMdBKh4fOeK nHYsoSMnZnIJ3tfgi7n9r/qH+HQa7fDBH6NdJ/RI9whFZjn/vBzCp1KDHul1NTDQ kwak9xnboPtFgXYmMmi8wolrecd3uGeJVD39794nxL17rZWG0nSsS3Ti4/++WsYf sDsZEyem6Gn/4HUXZAZxU20dOhlQGeCQkDfwQF5UH4ntaCaw6xhfPEdFU2BB+itH eWAYlKgRX2IPxvXlNShGG3tsLMMZRW1D4Lc4SCVa/pn9m1VOE74Vea0cNYVxxE4Y TFJKQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=UHZu0hr00LFyw79MEJKvUal7Ug1S1t8BwRdKFSyXE 4U=; b=CVrMuZmj5zys6XJrrB2l1CvVM79BoNrZ4KzCWoIR8DCENb+O2bZhFNrbk 9Zq2LbdCYDXb9fyxWYeBIba/yg/n6U0RsvC4pxSJ/uDHW9d4APnmvjLVYKbJEhSs Y92GDVcCGiT2i9bgPYWuHOwLIIK3UgXKC4MgG/Q5Y2lGMt3MevjgqIGnAqrLQbjm 7V7NGeM6o8U/s9HnLU1fjgnRLNRh5RWEEOzsPaoSxA5rMUPlLzaECc7VF0jP7f7Q qhf/gWfTgS16SeT1ktF54FHO2qb1xM/MF2BoYuqCLqpmgnnPM9Rn702/fdCNd8bq PcsrMqst07ieFpVW3fVASNDsPXo7A== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrgeehgdduvdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffvfhfhkffffgggjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucffohhmrghinhepvghnthhrhidrihgupdhtrghgrdhiugenucfkphepleejrddu udefrddvtdejrddufeeknecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrg hilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: from [192.168.1.10] (97-113-207-138.tukw.qwest.net [97.113.207.138]) by mail.messagingengine.com (Postfix) with ESMTPA id 57812328005A; Tue, 21 Apr 2020 14:28:32 -0400 (EDT) Subject: Re: Triggers and Full Text Search * To: Malik Rumi , Ericson Smith Cc: Andreas Joseph Krogh , pgsql-general@lists.postgresql.org References: From: Adrian Klaver Message-ID: <2b0a6696-c0bc-8abe-9822-58efddf8d44e@aklaver.com> Date: Tue, 21 Apr 2020 11:28:31 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 4/21/20 11:21 AM, Malik Rumi wrote: > @Ericson, > Forgive me for seeming dense, but how does COPY help or hurt here? > > @Andreas, > I had to laugh at your reference to "prose". Would you believe I am > actually a published playwright? Long before I started coding, of > course. Old habits die hard..... The script code via Python/Django/psycopg2 would be helpful as my suspicion is that you are seeing the effects of open transactions. > > entry_search_vector_trigger >             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 >                 LEFT JOIN ktab_tag AS tag ON tag.id = > entry_tags.tag_id >               WHERE entry.id = NEW.id >               GROUP BY entry.id , category; >               RETURN NEW; >             END; > > tag_search_vector_trigger >             BEGIN >               UPDATE ktab_entry SET id = id WHERE id IN ( >                 SELECT entry_id FROM ktab_entry_tags WHERE tag_id = NEW.id >               ); >               RETURN NEW; >             END; > > tags_search_vector_trigger >             BEGIN >               IF (TG_OP = 'DELETE') THEN >                 UPDATE ktab_entry SET id = id WHERE id = OLD.entry_id; >                 RETURN OLD; >               ELSE >                 UPDATE ktab_entry SET id = id WHERE id = NEW.entry_id; >                 RETURN NEW; >               END IF; >             END; > > search_vector_update >             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 >                 LEFT JOIN ktab_tag AS tag ON tag.id = > entry_tags.tag_id >               WHERE entry.id = NEW.id >               GROUP BY entry.id , category; >               RETURN NEW; >             END; > > search_vector_update  (tags) >             BEGIN >               IF (TG_OP = 'DELETE') THEN >                 UPDATE ktab_entry SET id = id WHERE id = OLD.entry_id; >                 RETURN OLD; >               ELSE >                 UPDATE ktab_entry SET id = id WHERE id = NEW.entry_id; >                 RETURN NEW; >               END IF; >             END; > > Thank you! > > > > */“None of you has faith until he loves for his brother or his neighbor > what he loves for himself.”/* > > > On Tue, Apr 21, 2020 at 1:05 PM Ericson Smith > wrote: > > I think COPY bypasses the triggers. > > Best Regards > - Ericson Smith > +1 876-375-9857 (whatsapp) > +1 646-483-3420 (sms) > > > > On Wed, Apr 22, 2020 at 12:32 AM Andreas Joseph Krogh > > wrote: > > På tirsdag 21. april 2020 kl. 19:24:10, skrev Malik Rumi > >: > > [...] > > I am not (yet) posting the trigger code because this post is > long already, and if your answers are 1) yes, 2) no and 3) > triggers often work / fail like this, then there’s no point > and we can wrap this up. But if not, I will happily post > what I have. Thank you. > > This is too much prose for the regular programmer, show us the > code, and point out what doesn't work for you, then we can help:-) > -- > Andreas Joseph Krogh > -- Adrian Klaver adrian.klaver@aklaver.com