473,287 Members | 3,319 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Trigger

Is it possible to deferr a trigger until commit, Or to have the
trigger not occur if the transaction is rolled back? Like transaction.
I think its possible since constraints use triggers and if so why
is this a standard feature.
Also is there anyway of seeing what triggers exsist and what they
do? (psql \<somthing> or the like)

Peter Childs

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 12 '05 #1
11 3016
On Wed, 22 Oct 2003, Peter Childs wrote:
Is it possible to deferr a trigger until commit, Or to have the
trigger not occur if the transaction is rolled back? Like transaction.
I think its possible since constraints use triggers and if so why
is this a standard feature.
Also is there anyway of seeing what triggers exsist and what they
do? (psql \<somthing> or the like)


A trigger inside a transaction should automagically roll back should the
transaction fail, shouldn't it?
---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 12 '05 #2
scott.marlowe writes:
A trigger inside a transaction should automagically roll back should the
transaction fail, shouldn't it?


The database actions that the trigger possibly executed are rolled back
just like any other database actions. But if your trigger does something
external to the database, you have a problem (that borders on
unsolvable).

--
Peter Eisentraut pe*****@gmx.net
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #3


On Wed, 22 Oct 2003, scott.marlowe wrote:
On Wed, 22 Oct 2003, Peter Childs wrote:
Is it possible to deferr a trigger until commit, Or to have the
trigger not occur if the transaction is rolled back? Like transaction.
I think its possible since constraints use triggers and if so why
is this a standard feature.
Also is there anyway of seeing what triggers exsist and what they
do? (psql \<somthing> or the like)


A trigger inside a transaction should automagically roll back should the
transaction fail, shouldn't it?


Only if it only affects that database. If the trigger uses C to
tell an outside app whats going on, it will not get the truth.
Background, we are trying to get the database to tell clients when
records get updated, deleted or inserted so that they can update there
on-screen displays without having to query the database every couple of
seconds which would put an unnessary strain on the database. Hence
producing quicker respose times.

Peter Childs

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 12 '05 #4
On Thu, Oct 23, 2003 at 08:16:27AM +0100, Peter Childs wrote:


On Wed, 22 Oct 2003, scott.marlowe wrote:
On Wed, 22 Oct 2003, Peter Childs wrote:
Is it possible to deferr a trigger until commit, Or to have the
trigger not occur if the transaction is rolled back? Like transaction.


Background, we are trying to get the database to tell clients when
records get updated, deleted or inserted so that they can update there
on-screen displays without having to query the database every couple of
seconds which would put an unnessary strain on the database. Hence
producing quicker respose times.


You should probably be using an AFTER trigger ... when those get
executed, the transaction is ready to commit and will not abort (barring
any major problems, like your server go nuts or something).

But why don't you use some notifications and set up appropiate listeners
on the OSDs? See the NOTIFY/LISTEN reference pages ... these also get
delivered during transaction commit.

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"In fact, the basic problem with Perl 5's subroutines is that they're not
crufty enough, so the cruft leaks out into user-defined code instead, by
the Conservation of Cruft Principle." (Larry Wall, Apocalypse 6)

---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Nov 12 '05 #5


On Thu, 23 Oct 2003, Alvaro Herrera wrote:
On Thu, Oct 23, 2003 at 08:16:27AM +0100, Peter Childs wrote:


On Wed, 22 Oct 2003, scott.marlowe wrote:
On Wed, 22 Oct 2003, Peter Childs wrote:

> Is it possible to deferr a trigger until commit, Or to have the
> trigger not occur if the transaction is rolled back? Like transaction.
Background, we are trying to get the database to tell clients when
records get updated, deleted or inserted so that they can update there
on-screen displays without having to query the database every couple of
seconds which would put an unnessary strain on the database. Hence
producing quicker respose times.


You should probably be using an AFTER trigger ... when those get
executed, the transaction is ready to commit and will not abort (barring
any major problems, like your server go nuts or something).


Using an After trigger but the transactions may still rollback. a
subsquent query may fail before commit or a constraint may fail.

But why don't you use some notifications and set up appropiate listeners
on the OSDs? See the NOTIFY/LISTEN reference pages ... these also get
delivered during transaction commit.
Great idea shame drivers to get at these are rare. Anyway you
still need a trigger to fire the notify and these get sent when the query
is done not when its commented. hmmm
Peter Childs

--
Alvaro Herrera (<alvherre[a]dcc.uchile.cl>)
"In fact, the basic problem with Perl 5's subroutines is that they're not
crufty enough, so the cruft leaks out into user-defined code instead, by
the Conservation of Cruft Principle." (Larry Wall, Apocalypse 6)


---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #6
Peter Childs <bl*********@blueyonder.co.uk> writes:
Background, we are trying to get the database to tell clients when
records get updated, deleted or inserted so that they can update there
on-screen displays without having to query the database every couple of
seconds which would put an unnessary strain on the database.


Use LISTEN/NOTIFY.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to ma*******@postgresql.org)

Nov 12 '05 #7
Peter Childs <bl*********@blueyonder.co.uk> writes:
Great idea shame drivers to get at these are rare. Anyway you
still need a trigger to fire the notify and these get sent when the query
is done not when its commented. hmmm


But the NOTIFY isn't delivered until and unless the transaction commits.
This gets around the AFTER-trigger-can-still-roll-back problem.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Nov 12 '05 #8
On Thu, 23 Oct 2003, Alvaro Herrera wrote:
On Thu, Oct 23, 2003 at 08:16:27AM +0100, Peter Childs wrote:


On Wed, 22 Oct 2003, scott.marlowe wrote:
On Wed, 22 Oct 2003, Peter Childs wrote:

> Is it possible to deferr a trigger until commit, Or to have the
> trigger not occur if the transaction is rolled back? Like transaction.


Background, we are trying to get the database to tell clients when
records get updated, deleted or inserted so that they can update there
on-screen displays without having to query the database every couple of
seconds which would put an unnessary strain on the database. Hence
producing quicker respose times.


You should probably be using an AFTER trigger ... when those get
executed, the transaction is ready to commit and will not abort (barring
any major problems, like your server go nuts or something).


This is not true, actually. After triggers generally happen at the end of
statement (with the exception of deferred constraint triggers and some
wierdness with functions) and can themselves throw an exception condition
so even barring internal problems, it's unsafe to assume that an exception
won't happen after your trigger runs.

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #9


On Thu, 23 Oct 2003, Tom Lane wrote:
Peter Childs <bl*********@blueyonder.co.uk> writes:
Great idea shame drivers to get at these are rare. Anyway you
still need a trigger to fire the notify and these get sent when the query
is done not when its commented. hmmm


But the NOTIFY isn't delivered until and unless the transaction commits.
This gets around the AFTER-trigger-can-still-roll-back problem.

regards, tom lane

Notify is also not very flexable it tells you somthing has
triggerged it not the information that a trigger is supplied with, like
what has changed to what from what.

Peter Childs

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #10
On Thu, 23 Oct 2003, Peter Childs wrote:


On Wed, 22 Oct 2003, scott.marlowe wrote:
On Wed, 22 Oct 2003, Peter Childs wrote:
Is it possible to deferr a trigger until commit, Or to have the
trigger not occur if the transaction is rolled back? Like transaction.
I think its possible since constraints use triggers and if so why
is this a standard feature.
Also is there anyway of seeing what triggers exsist and what they
do? (psql \<somthing> or the like)


A trigger inside a transaction should automagically roll back should the
transaction fail, shouldn't it?


Only if it only affects that database. If the trigger uses C to
tell an outside app whats going on, it will not get the truth.
Background, we are trying to get the database to tell clients when
records get updated, deleted or inserted so that they can update there
on-screen displays without having to query the database every couple of
seconds which would put an unnessary strain on the database. Hence
producing quicker respose times.


It might be more efficient and transactionally safe to write it all to a
temp table, and have a daemon suck that data out every now and then and
put it into another database that the feeders can interrogate as often as
they like. that way you still get the ease of programming a transaction
that's all or nothing, and since the daemon only runs every minute or two
and batches up its access, the impace of the batching should be nominal.
Or would that introduce other problems of its own?
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 12 '05 #11


On Thu, 23 Oct 2003, scott.marlowe wrote:
It might be more efficient and transactionally safe to write it all to a
temp table, and have a daemon suck that data out every now and then and
put it into another database that the feeders can interrogate as often as
they like. that way you still get the ease of programming a transaction
that's all or nothing, and since the daemon only runs every minute or two
and batches up its access, the impace of the batching should be nominal.
Or would that introduce other problems of its own?

Makes the whole trigger alot more complex. Also got to work out
when to remove rows. Plus a load of programming to get notify to work
properly. Yuk.

I think the simplest way then is going to be. That your
surgesting.

Write Trigger to Write info to table and notify each row needs a unique
id.

Listening Program reads table and records another id to say its
listening and how far its got, Waits for notify then checks the table
again and records the id. Fortinally each transaction only emits one
notify no matter how many times notify got called.

Program three looks for all ids in table below the lowest id listen and
deletes them, this should keep the table small enough to use.

Where as my orignal plan was using a deffered after trigger emit
the data down a pipe then all the program needs to do is listen to the
pipe.

Both plans have advantages the main oneof mine being its simple.

Peter
Trying to follow a kiss policy.

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to ma*******@postgresql.org

Nov 12 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Matik | last post by:
Hello to all, I have a small question. I call the SP outer the DB. The procedure deletes some record in table T1. The table T1 has a trigger after delete. This is very importand for me, that...
6
by: Scott CM | last post by:
I have a multi-part question regarding trigger performance. First of all, is there performance gain from issuing the following within a trigger: SELECT PrimaryKeyColumn FROM INSERTED opposed...
9
by: Martin | last post by:
Hello, I'm new with triggers and I can not find any good example on how to do the following: I have two tables WO and PM with the following fields: WO.WONUM, VARCHAR(10) WO.PMNUM,...
6
by: Mary | last post by:
We are developing a DB2 V7 z/OS application which uses a "trigger" table containing numerous triggers - each of which is activated by an UPDATE to a different column of this "trigger" table. When...
0
by: Dave Sisk | last post by:
I've created a system or external trigger on an AS/400 file a.k.a DB2 table. (Note this is an external trigger defined with the ADDPFTRG CL command, not a SQL trigger defined with the CREATE...
0
by: JohnO | last post by:
Thanks to Serge and MarkB for recent tips and suggestions. Ive rolled together a few stored procedures to assist with creating audit triggers automagically. Hope someone finds this as useful as...
1
by: deepdata | last post by:
Hi, I am creating a trigger in DB2 express version. When i use the following syntax to create trigger CREATE TRIGGER USER_PK_TRIGGER BEFORE INSERT On users REFERENCING NEW As N FOR EACH...
9
by: Ots | last post by:
I'm using SQL 2000, which is integrated with a VB.NET 2003 app. I have an Audit trigger that logs changes to tables. I want to apply this trigger to many different tables. It's the same trigger,...
7
by: Shane | last post by:
I have been instructed to write a trigger that effectively acts as a foreign key. The point (I think) is to get me used to writing triggers that dont use the primary key(s) I have created the...
11
by: tracy | last post by:
Hi, I really need help. I run this script and error message appeal as below: drop trigger log_errors_trig; drop trigger log_errors_trig ERROR at line 1: ORA04080: trigger 'LOG_ERRORS-TRIG'...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.