Trigger Update Issue - Mailing list pgsql-general

From beer
Subject Trigger Update Issue
Date
Msg-id 37575.192.88.209.232.1078495251.squirrel@webmail.andrew.cmu.edu
Whole thread Raw
Responses Re: Trigger Update Issue
Re: Trigger Update Issue
List pgsql-general
Hello All

I'm running 7.3.4-1 on a RH9 box.  I'm having a problem with a trigger
that seems to execute without actually performing the update that it
should.  The update returns true everytime however if it is the first time
that the trigger executes on a given row, the column is not updated.  The
column is updated correctly on subsequent calls.

Here is the code:

create table tabA (
  id     char(32) primary key not null,
  Acol1   char(40) not null unique,
  Acol2   integer not null,
  Acol3   integer default 0 check ( Acol3 >= 0),
);

create table tabB (
  id            integer default nextval('tabB_id_seq'::text)
                not null check (id > 0) primary key,
  tabA_id       char(32) not null references tabA (id)
                on delete cascade on update cascade,
  Bcol1          text default null,
  Bcol2          text default null,
);


CREATE OR REPLACE FUNCTION "tabB_postinsert" () RETURNS TRIGGER AS '
  --
  -- Actions to take after inserting into tabB
  --
  BEGIN
    -- Increment tabA.attachments
    UPDATE tabA SET Acol3 = Acol3 + 1 WHERE id = NEW.tabA_id;
    -- done
    RETURN NEW;
  END; ' LANGUAGE 'plpgsql';

CREATE TRIGGER "master_tabB_postinsert"
  AFTER INSERT ON "tabB"
  FOR EACH ROW EXECUTE PROCEDURE "tabB_postinsert" ();

I am using this same trigger structure on other tables without having any
issues.  Any insight would be greatly appreciated.

Thanks

-b

pgsql-general by date:

Previous
From: "Gellert, Andre"
Date:
Subject: Re: Are Postgres 7.4.1 RPMs available for SuSE 9.0 ?
Next
From: phil campaigne
Date:
Subject: Setting up Postgres on Linux