pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Omkar Rath <orath@cisco.com>
To: pgsql-sql@postgresql.org
Subject: Sequence of SQL command execution involving triggers and stored procedures.
Date: Fri, 17 Sep 2004 23:54:24 -0500
Message-ID: <F67EB38120F7BB4BB972C7860958020704E5747F@ipcbu-exchange.amer.unity.cisco.com> (raw)

I am observing the following:
 
Say there is a stored procedure i.e FUNCTION sp_foo(...) which has say,
SQL commands (any of SELECT,INSERT,UPDATE,DELETE) in its body, say S1
followed by S2 then S3.... Furthermore, execution of statement S2
results in trigger functions getting invoked (that contain yet other SQL
statements).
 
By the time, the trigger functions execute (as a result of S2), S3 has
already executed.
 
Note that sp_foo() was invoked via a SELECT i.e SELECT sp_foo(...).
 
To work around this "behaviour", I wrapped sp_foo() within another
FUNCTION say sp_foo_wrapper(...) and in the body of sp_foo_wrapper() I
did this -
 
1. INSERT <something> in a scratch table // akin to setting a flag
2. Invoke sp_foo().
3. DELETE <something> from the scratch table // akin to resetting the
flag
 
Even then, by the time the triggers fired as a result of S2 (in the body
of sp_foo), the DELETE (in step 3 above) had executed.
 
Questions:
1. Did I miss something very basic?
 
2. Is this behavior random i.e the manifestation pertians to the
particular SQL commands in my code?
 
3. How does one achieve, the chronolgy that I want i.e I want S3 AND/OR
step 3 to occur AFTER the triggers (as a result of S2) to fire?
 
Thanx in advance,
 
 
 
Omkar Rath
Software Engr.
VTG
Cisco Systems Inc.

view thread (2+ messages)  latest in thread

Message-ID: <F67EB38120F7BB4BB972C7860958020704E5747F@ipcbu-exchange.amer.unity.cisco.com>
Permalink:  ../F67EB38120F7BB4BB972C7860958020704E5747F@ipcbu-exchange.amer.unity.cisco.com/
Also on:    postgresql.org/message-id/F67EB38120F7BB4BB972C7860958020704E5747F@ipcbu-exchange.amer.unity.cisco.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: orath@cisco.com
  Subject: Re: Sequence of SQL command execution involving triggers and stored procedures.
  In-Reply-To: <F67EB38120F7BB4BB972C7860958020704E5747F@ipcbu-exchange.amer.unity.cisco.com>
  References: <F67EB38120F7BB4BB972C7860958020704E5747F@ipcbu-exchange.amer.unity.cisco.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox