Thread: Recursive call indicator/counter
Gudday' all. In plpgsql, I've written a function that can call itself if necessary and thus recurse down to the bottom of a tree, operate on bottom node, then as it comes out, operate on each node, until eventually it gets to the top again. However, is there any system variable that I can check to see if this function has just been called for the first time or if this is the nTH call from itself? Thanks. -- Hadley Willan > Systems Development > Deeper Design Limited. hadley@deeper.co.nz > www.deeperdesign.com > +64 (21) 28 41 463
You could add a 'depth' parameter, and when you call it again, pass in depth + 1. ----- Original Message ----- From: "Hadley Willan" <hadley.willan@deeper.co.nz> To: "Postgresql General" <pgsql-general@postgresql.org> Sent: Friday, November 08, 2002 3:38 PM Subject: [GENERAL] Recursive call indicator/counter > Gudday' all. > > In plpgsql, I've written a function that can call itself if > necessary and thus recurse down to the bottom of a tree, operate on > bottom node, then as it comes out, operate on each node, until > eventually it gets to the top again. > > However, is there any system variable that I can check to see if this > function has just been called for the first time or if this is the nTH > call from itself? > > Thanks. > -- > Hadley Willan > Systems Development > Deeper Design Limited. > hadley@deeper.co.nz > www.deeperdesign.com > +64 (21) 28 41 463 > > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org >
You can also write the function in plpython. Plpython has the concept of a statement duration data dictionary. Since the calls are recursive they should all be in the same SQL statement duration. This is also a very handy way to write running sums, etc. elein@norcov.com On Thursday 07 November 2002 18:38, Hadley Willan wrote: > Gudday' all. > > In plpgsql, I've written a function that can call itself if > necessary and thus recurse down to the bottom of a tree, operate on > bottom node, then as it comes out, operate on each node, until > eventually it gets to the top again. > > However, is there any system variable that I can check to see if this > function has just been called for the first time or if this is the nTH > call from itself? > > Thanks.