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>
Re: after update trigger ? tmoore <tmoore@ttitech.net>
Re: after update trigger ? Tom Lane <tgl@sss.pgh.pa.us>
Re: after update trigger ? raghu ram <raghuchennuru@gmail.com>


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 ?
FAQ