INSERT trigger updating the inserted row
Posted in 1999
Topics: Triggers, Constraints & Referential Integrity
Is it possible (and how) to set a column of a newly inserted row to a
calculated column?
I wanted to something like
create trigger po_dateINSERT ON table1
REFERENCING new AS post
FOR EACH ROW WHEN (post.supplier ="123456")
(UPDATE table1 SET date_required = TODAY + 14 UNITS DAY)
I know this is not allowed. I have to do it on SQL base, since we cannot
change the application,
but how can I achive it?
Very urgent!
TIA,
Kai
i have the same problem. i could do a workaround by detecting the insert not
in the table itself but in a joined table. this worked with a local se 7.2
server. but it doesnt work with our online 7.3 server. ...
tom
Kai_Shen@acer.de wrote:
> Is it possible (and how) to set a column of a newly inserted row to a
> calculated column?
> I wanted to something like
>
> create trigger po_date> INSERT ON table1
> REFERENCING new AS post
> FOR EACH ROW WHEN (post.supplier ="123456")
> (UPDATE table1 SET date_required = TODAY + 14 UNITS DAY)
>
> I know this is not allowed. I have to do it on SQL base, since we cannot
> change the application,
> but how can I achive it?
>
> Very urgent!
>
> TIA,
> Kai
Thomas Vatter wrote:
>
> i have the same problem. i could do a workaround by detecting the insert not
> in the table itself but in a joined table. this worked with a local se 7.2
> server. but it doesnt work with our online 7.3 server. ...
Actually 7.30+ now supports updating the inserted row from within an
INSERT trigger!
Beond that I'd suggest you have the trigger execute a stored procedure
that signals an external server program (perhaps by calling a shell
script to echo the rowid or key columns to a named pipe that the server
monitors). The server would then go in and modify the recently added
row, if the server is resident the delay between commit and update
should be barely detectable.
> tom
>
> Kai_Shen@acer.de wrote:
>
> > Is it possible (and how) to set a column of a newly inserted row to a
> > calculated column?
> > I wanted to something like
> >
> > create trigger po_date> > INSERT ON table1
> > REFERENCING new AS post
> > FOR EACH ROW WHEN (post.supplier ="123456")
> > (UPDATE table1 SET date_required = TODAY + 14 UNITS DAY)
> >
> > I know this is not allowed. I have to do it on SQL base, since we cannot
> > change the application,
> > but how can I achive it?
> >
> > Very urgent!
> >
> > TIA,
> > Kai