Re: after update trigger ?

Поиск
Список
Период
Сортировка
От raghu ram
Тема Re: after update trigger ?
Дата
Msg-id BANLkTi=xusL9fN+hzG7+AzDs9wkDFOqdJA@mail.gmail.com
обсуждение исходный текст
Ответ на after update trigger ?  (tmoore <tmoore@ttitech.net>)
Список pgsql-novice


On Fri, Apr 22, 2011 at 7:23 PM, tmoore <tmoore@ttitech.net> wrote:
Can an after update trigger function do an insert into the the same table ?


Yes, we can do  and code snippet as follows::

1. Fetch records from Existing Table

postgres=# SELECT * FROM NEW_EMP;
eno | ename  |  sal
-----+--------+-------
  1 | xx |  9000
  2 | ABC | 90000
(2 rows)

2. Create a function
CREATE OR REPLACE FUNCTION RAGHU() RETURNS TRIGGER
AS
$$
BEGIN
INSERT INTO NEW_EMP VALUES(1,'RAGHU',90000);
RETURN NEW;
END;
$$
LANGUAGE PLPGSQL;

3. Create a trigger
CREATE TRIGGER RAGHU_TRI AFTER UPDATE ON NEW_EMP FOR EACH ROW
EXECUTE PROCEDURE RAGHU();

4. Update the records in "NEW_EMP" table

postgres=# UPDATE NEW_EMP SET ENAME='RAJESH' WHERE ENO=2;
UPDATE 1

5. Fetch Records from "NEW_EMP" Table

postgres=# SELECT * FROM NEW_EMP;
eno | ename  |  sal
-----+--------+-------
  1 | XX |  9000
  2 | RAJESH | 90000
  1 | RAGHU  | 90000



Thanks & Regards
Raghu Ram
EnterpriseDB Corporation
The Enterprise PostgreSQL Company
 

Thanks
Tom


--
View this message in context: http://postgresql.1045698.n5.nabble.com/after-update-trigger-tp4333008p4333008.html
Sent from the PostgreSQL - novice mailing list archive at Nabble.com.

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

В списке pgsql-novice по дате отправления:

Предыдущее
От: tmoore
Дата:
Сообщение: Re: after update trigger ?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: after update trigger ?