From: | Parthan <python(dot)technofreak(at)gmail(dot)com> |
---|---|
To: | PostgreSQL general <pgsql-general(at)postgresql(dot)org> |
Subject: | Simple Trigger Error |
Date: | 2006-12-20 04:01:54 |
Message-ID: | 4588B5B2.6050403@gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi,
I am trying to create a simple trigger which inserts a couple of fields
into a table, when data in inserted into another table.
I have two tables, 'addressbook' and 'phonebook'. When I insert data
into the addressbook (whose fields are name, address1, address2,
address3, phonenum), I want it to add 'name' and 'phonenum' field values
into 'phonebook' table.
The following is the trigger i wrote for the above..
---- Begin of Code ---
DROP TRIGGER phonebook on addressbook;
CREATE OR REPLACE FUNCTION add_to_phonebook() RETURNS TRIGGER AS $phonebook$
DECLARE
new_name varchar;
new_phone varchar;
BEGIN
IF(TG_OP='INSERT') THEN
INSERT INTO phonebook(name,phonenum)
VALUES(NEW.name,NEW.phonenum);
END IF;
RETURN NEW;
END;
$phonebook$ LANGUAGE plpgsql;
CREATE TRIGGER phonebook AFTER INSERT ON addressbook FOR EACH ROW
EXECUTE PROCEDURE add_to_phonebook();
----- End of code ---
I created the two tables as follows
'addressbook'
id serial | name varchar(100) | address1 varchar(100) | address2
varchar(100) | address3 varchar(100) | phonenum varchar(15)
'phonebook'
id serial | name varchar(100) | phonenum varchar(100)
Now, when I try to insert data into the addressbook and the trigger
runs, I get into an ever ending process accompanied by following in my
terminal where I run it:
""SQL statement "INSERT INTO phonebook(name,phonenum) VALUES( $1 , $2 )"
PL/pgSQL function "add_to_phonebook" line 7 at SQL statement""
When this happens, my processor runs at 100% and when I press Ctrl+C, it
continues for few seconds and I get my terminal gets filled with the
above stated message. Also that, the original 'insert into' operation
over the 'addressbook' table doesn't happen.
Where am I wrong in the trigger function ?
--
With Regards
Parthan (TechnoFreak)
. A Proud GNU/Linux User and Ubuntero
.0.
..0 [Web] https://wiki.ubuntu.com/Parthan
000 [Blog]http://technofreakatchennai.wordpress.com
From | Date | Subject | |
---|---|---|---|
Next Message | A. Kretschmer | 2006-12-20 06:47:53 | Re: Simple Trigger Error |
Previous Message | Matt Burry | 2006-12-20 03:47:09 | Re: postgres kerberos how to |