Re: Triggers and Function's

From: "scott(dot)marlowe" <scott(dot)marlowe(at)ihs(dot)com>
To: Campos Chaves <camposchaves(at)yahoo(dot)com(dot)br>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: Triggers and Function's
Date: 2003-05-28 22:05:35
Message-ID: Pine.LNX.4.33.0305281559530.28136-100000@css120.ihs.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Hadley Willan 2003-05-28 22:18:56 Re: Can anybody recommend an IDE for writing SQL/PLPSQL
Previous Message Fabrizio Mazzoni 2003-05-28 21:45:58 Re: Triggers and Function's