pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Calling a SP from Curosor loop
2+ messages / 2 participants
[nested] [flat]

* Calling a SP from Curosor loop
@ 2006-06-29 17:00  satishchandra999@gmail.com
  0 siblings, 1 reply; 2+ messages in thread

From: satishchandra999@gmail.com @ 2006-06-29 17:00 UTC (permalink / raw)
  To: pgsql-performance

I have SP, which has a cursor iterations. Need to call another SP for
every loop iteration of the cursor. The pseudo code is as follows..

Create proc1 as
Begin

Variable declrations...

declare EffectiveDate_Cursor cursor for
select field1,fld2 from tab1,tab2 where tab1.effectivedate<Getdate()
---/////Assuming the above query would result in 3 records
Open EffectiveDate_Cursor
Fetch next From EffectiveDate_Cursor Into @FLD1,@FLD2
begin
    /*Calling my second stored proc with fld1 as a In parameter
and Op1 and OP2 Out parameters*/
    Exec sp_minCheck @fld1, @OP1 output,@OP2 output
     Do something based on Op1 and Op2.
end
While @@Fetch_Status = 0
Fetch next From EffectiveDate_Cursor Into @FLD1,@FLD2
/* Assume If loop count is 3.
 and If the Fetch stmt is below the begin Stmt, the loop iterations are
4 else the loop iterations are 2*/
begin
    /*Calling my second stored proc with fld1 as a In parameter and Op1
and OP2 Out parameters*/
    Exec sp_minCheck @fld1, @OP1 output,@OP2 output
     Do something based on Op1 and Op2.
end


The problem I had been facing is that, the when a stored proc is called
within the loop, the proc is getting into infinite loops.
Any Help would be appreciated.

Satish




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Calling a SP from Curosor loop
@ 2006-07-07 13:21  Merlin Moncure <mmoncure@gmail.com>
  parent: satishchandra999@gmail.com
  0 siblings, 0 replies; 2+ messages in thread

From: Merlin Moncure @ 2006-07-07 13:21 UTC (permalink / raw)
  To: pgsql-performance

On 29 Jun 2006 10:00:35 -0700, satishchandra999@gmail.com
<satishchandra999@gmail.com> wrote:
> I have SP, which has a cursor iterations. Need to call another SP for
> every loop iteration of the cursor. The pseudo code is as follows..

i would suggest converting your code to pl/pgsql and reposting.  that
look awfully like t-sql stored procedure, you may as well be saying,
'gobble de gook bak wakka bakka bak!', got it? :-)

(aside: pg/pgsql functions support nested calls, recursion, etc and
should provide no problems when properly written).

merlin



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2006-07-07 13:21 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-06-29 17:00 Calling a SP from Curosor loop satishchandra999@gmail.com
2006-07-07 13:21 ` Merlin Moncure <mmoncure@gmail.com>

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