Triggers not working - Mailing list pgsql-general

From Dale Harris
Subject Triggers not working
Date
Msg-id 006c01c91c66$50a62f00$f1f28d00$@com.au
Whole thread Raw
Responses Re: Triggers not working  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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();

pgsql-general by date:

Previous
From: Craig Ringer
Date:
Subject: Re: i can't drop an idex
Next
From: Keaton Adams
Date:
Subject: Largest PostgreSQL 8.x DB someone is running?