Re: Triggers and Function's

Поиск
Список
Период
Сортировка
Искать
От
scott.marlowe
Тема
Re: Triggers and Function's
Дата
в 18:21:57
Msg-id
Pine.LNX.4.33.0305281559530.28136-100000@css120.ihs.com
Ответ на
Triggers and Function's (Campos Chaves)
Список
Дерево обсуждения
Triggers and Function's Campos Chaves <camposchaves@yahoo.com.br>
Re: Triggers and Function's Ewald Geschwinde <webmaster@geschwinde.net>
Re: Triggers and Function's Fabrizio Mazzoni <mazzofab@tiscalinet.it>
Re: Triggers and Function's <btober@seaworthysys.com>
Re: Triggers and Function's "scott.marlowe" <scott.marlowe@ihs.com>
On Wed, 28 May 2003, Campos Chaves wrote:

> Hi,
> 
> After I insert on rocord on Table A, I need to insert
> another record on Table B. I think that I have to use
> triggers and functions. But I don't know how! You can
> help me?

You can either do it by hand in a transaction, or in something like 
plpgsql / triggers.

To do it by hand, you do:

begin;
insert into table a (
	field1,
	field2,
	idfield
) values (
	'data',
	number,
	nextval('sequence')
);
insert into table b (
	fielda,
	fieldb,
	fktotable1
) values (
	'date',
	number3,
	currval('sequence')
);
commit;

Just make the whole thing a plsql function and feed it all the data it 
needs and you don't have to worry about anything but checking for errors 
in your app. 

If you need to update other tables based on some kind of caclulation, then 
you'll be needing triggers or rules.

В списке pgsql-general по дате отправления
От: Hadley Willan
Дата:
От: Andy Kriger
Дата:
FAQ