Triggers not working

From: "Dale Harris" <itsupport(at)jonkers(dot)com(dot)au>
To: <pgsql-general(at)postgresql(dot)org>
Subject: Triggers not working
Date: 2008-09-22 03:50:09
Message-ID: 006c01c91c66$50a62f00$f1f28d00$@com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi,

I'm running PostgreSQL 8.3.3 and I'm having trouble with triggers not always
working. I have the following tables and functions as documented below. My
problem is that if I perform an update on the Entity table and modify the
Code field, why doesn't the trigger for the Entity table execute? (Row was
initially added via the Account table.)

Dale.

CREATE TABLE "Entity"

(

"ID" bigserial NOT NULL,

"Code" character varying(20) NOT NULL,

"Name" character varying(50) NOT NULL,

"Modified" timestamp(1) with time zone NOT NULL DEFAULT
session_timestamp(),

"ModifiedBy" bigint DEFAULT userid(),

CONSTRAINT "pkEntity" PRIMARY KEY ("ID")

);

CREATE TABLE "Account"

(

"Balance" money NOT NULL DEFAULT '$0.00'::money,

CONSTRAINT "pkAccount" PRIMARY KEY ("ID"),

CONSTRAINT "uniqAccountCode" UNIQUE ("Code")

)

INHERITS ("Entity");

CREATE OR REPLACE FUNCTION entitytrigger() RETURNS trigger AS

$BODY$BEGIN

--Update modified details

raise notice '% being called for % of %.', TG_NAME, TG_OP, TG_TABLE_NAME;

new."Modified" := Session_TimeStamp();

new."ModifiedBy" := UserID();

return new;

END;$BODY$

LANGUAGE 'plpgsql' VOLATILE;

CREATE TRIGGER "trEntityUpdate"

BEFORE UPDATE

ON "Entity"

FOR EACH ROW

EXECUTE PROCEDURE entitytrigger();

CREATE TRIGGER "trAccountUpdate"

BEFORE UPDATE

ON "Account"

FOR EACH ROW

EXECUTE PROCEDURE entitytrigger();

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2008-09-22 04:11:52 Re: i can't drop an idex
Previous Message Dean Grubb 2008-09-22 03:35:26 PL/Python - Execute return results