Trigger Update Issue

From: "beer" <beer(at)cmu(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Subject: Trigger Update Issue
Date: 2004-03-05 14:00:51
Message-ID: 37575.192.88.209.232.1078495251.squirrel@webmail.andrew.cmu.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message phil campaigne 2004-03-05 14:29:12 Setting up Postgres on Linux
Previous Message Gellert, Andre 2004-03-05 13:45:59 Re: Are Postgres 7.4.1 RPMs available for SuSE 9.0 ?