Re: Rows are repeating by the trigger function

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Kiran <bangalore(dot)kiran(at)gmail(dot)com>, Alban Hertroys <haramrae(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Rows are repeating by the trigger function
Date: 2016-10-31 17:51:27
Message-ID: bb731a4e-7dbb-3900-6e2a-1ce75317022b@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 10/31/2016 10:02 AM, Kiran wrote:
> Dear Adrian and Alban,
>
> Thanks for the suggestions.
> I revisited the entire tables, triggers related to the tables. I did not
> find anything strange.
> But, I removed all the rows from the* *cf_user_question_link and
> inserted relevant rows into the table from *cf_question*.
>
>
> Also, I recreated the function without the update and deployed it.
> Now the trigger function works as expected ( when a new row is inserted
> into the *cf_question*, a row with necessary fields is inserted into
> the cf_user_question_link table)
>
> Though now the trigger function works as expected but the issue that I
> faced was it because there were rows already in the cf_question table
> before the trigger function was deployed ?

Not really, the issue, as Alban pointed out, was you had UPDATE in the
trigger statement. So every time you did an UPDATE to cf_question you
got an INSERT into cf_user_question_link. So I suspect somewhere/somehow
you did 3 UPDATES to all the rows in cf_question while you had the old
trigger statement deployed.

>
> regards
> Kiran
>
>
>
>
> On Mon, Oct 31, 2016 at 3:45 PM, Alban Hertroys <haramrae(at)gmail(dot)com
> <mailto:haramrae(at)gmail(dot)com>> wrote:
>
> On 31 October 2016 at 14:41, Adrian Klaver
> <adrian(dot)klaver(at)aklaver(dot)com <mailto:adrian(dot)klaver(at)aklaver(dot)com>> wrote:
> > On 10/31/2016 02:06 AM, Kiran wrote:
> >> I know 94 = 1 + (3 * 31).
> >> I am just having a normal insert statement into cf_question table.
> >
> > Are there any other triggers on the tables?
>
> I'm fairly confident that the duplicates are from updates on the
> cf_question table. Since the trigger also fires on update and then
> inserts another record, that would explain the duplication pretty
> well.
>
> Nevertheless, if there are other triggers those bear investigation.
> --
> If you can't see the forest for the trees,
> Cut the trees and you'll see there is no forest.
>
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message John DeSoi 2016-10-31 18:09:51 Re: Way to quickly detect if database tables/columns/etc. were modified?
Previous Message Daniel Verite 2016-10-31 17:50:49 Re: initdb createuser commands