Unix Technical Forum

Trigger function is not called

This is a discussion on Trigger function is not called within the Pgsql General forums, part of the PostgreSQL category; --> Bill wrote: > The thing that has me confused is that the following table, trigger > and trigger function ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #11 (permalink)  
Old 08-27-2008, 07:08 AM
Klint Gore
 
Posts: n/a
Default Re: Trigger function is not called

Bill wrote:
> 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.

Perhaps explain verbose on the insert will make things clearer. When
the domain is used, there's a COERCETODOMAIN step that gets the constant
into the domain type. With the not null definition in the domain, this
blows up before anything else has a chance.

begin;

create schema test;
create sequence test.id_seq;
create domain mydom as bigint not null;

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

CREATE TABLE test.trigger_test2
(
"key" mydom,
data character varying(16),
CONSTRAINT trigger_test_key2 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();

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

explain verbose insert into test.trigger_test values (null,'hi');
--explain verbose insert into test.trigger_test2 values (null,'hi');

klint.

--
Klint Gore
Database Manager
Sheep CRC
A.G.B.U.
University of New England
Armidale NSW 2350

Ph: 02 6773 3789
Fax: 02 6773 3266
EMail: kgore4@une.edu.au


--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads for: Trigger function is not called

Thread Thread Starter Forum Replies Last Post
finding schema of table that called a trigger Jeff Hoffmann pgsql Sql 1 04-19-2008 12:05 PM
help with plpgsql function called by trigger Heather Johnson Pgsql General 3 04-08-2008 09:05 PM
procedure called by trigger can't see new data tacrawford@adelphia.net Oracle Miscellaneous 9 04-08-2008 11:59 AM
Retrieving Result Set from Dynamically called Stored Procedure or function in a Function Mark Oueis SQL Server 0 02-29-2008 03:32 AM
Returning exceptions from a SP called from a Trigger... Paul Reddin DB2 2 02-26-2008 07:53 PM


All times are GMT. The time now is 11:56 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com