Re: Trigger function is not called - Mailing list pgsql-general

From Bill
Subject Re: Trigger function is not called
Date
Msg-id 48B37041.9020908@dbginc.com
Whole thread Raw
In response to Re: Trigger function is not called  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Trigger function is not called
Re: Trigger function is not called
List pgsql-general
Tom Lane wrote:
Bill <pg@dbginc.com> writes: 
I removed the domain from the category_id and version columns leaving 
the following table, trigger function and trigger. The trigger function 
is still not called when I insert a new row. Any other ideas?   
You're still expecting the trigger to get invoked before any constraints
are enforced (the NOT NULLs being the problem here, I think).  Again,
you can enforce things through a trigger or through a table constraint,
but mixing and matching won't work too well.
		regards, tom lane

 
The thing that has me confused is that the following table, trigger and trigger function work perfectly and the primary key for this table is also bigint not null. I added a bigint not null domain to this schema and changed the data type of the key to the domain and then I get the constraint violation. I changed the type of the key column back to bigint not null and the trigger fires and no error occurs.

Bill

CREATE TABLE test.trigger_test
(
  "key" bigint NOT NULL,
  data character varying(16),
  CONSTRAINT trigger_test_key PRIMARY KEY (key)
)

CREATE OR REPLACE FUNCTION test.trigger_test_before_insert()
  RETURNS trigger AS
$BODY$
begin
  raise notice '*****Test before insert*****';
  new."key" := nextval('test.id_seq');
  return new;
end;
$BODY$
  LANGUAGE 'plpgsql' VOLATILE


CREATE TRIGGER trigger_test_insert
  BEFORE INSERT
  ON test.trigger_test
  FOR EACH ROW
  EXECUTE PROCEDURE test.trigger_test_before_insert();


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Trigger function is not called
Next
From: Tom Lane
Date:
Subject: Re: Trigger function is not called