pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rod Taylor <rbt@rbt.ca>
To: Stefano Vita Finzi <stefano.vita@pronesis.it>
Cc: pgsql-sql@postgresql.org
Subject: Re: plpgsql recursion
Date: 22 May 2003 21:59:43 -0400
Message-ID: <1053655182.279.28.camel@jester> (raw)
In-Reply-To: <01a601c31ef0$4a628220$0600a8c0@stefano>
References: <01a601c31ef0$4a628220$0600a8c0@stefano>

>       IF t_rec.node = testing THEN
>         RETURN ''Circular'';
>       ELSE
>         PERFORM dba_test(t_rec.node,testing);
>       END IF;
> I would use this function BEFORE inserting the new row. But if i try SELECT
> dba_test(4,1); i don't have the result i expect. Can i you give me an hint
> where am i wrong?

It's probably working as it's written :)  Once it finds 'Curcular' and
returns it to the recursed call of dba_test, you immediately throw away
the return value.

PERFORM should probably be replaced with:

ELSE
  -- ret is a variable
  SELECT dba_test(t_rec.node, testing) INTO ret;

  IF ret = ''Circular'' THEN
    RETURN ret;
  END IF;
END IF;


More to the point, if you're attempting to prevent circular items, and
this function will be used in the form of a trigger, then simply RAISE
EXCEPTION.  This way you can ignore having to deal with returned values.


-- 
Rod Taylor <rbt@rbt.ca>

PGP Key: http://www.rbt.ca/rbtpub.asc

Attachments:

  signature.asc (application/pgp-signature, 186B) download

view thread (5+ messages)  latest in thread

Message-ID: <1053655182.279.28.camel@jester>
Permalink:  ../1053655182.279.28.camel@jester/
Also on:    postgresql.org/message-id/1053655182.279.28.camel@jester

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: rbt@rbt.ca, stefano.vita@pronesis.it
  Subject: Re: plpgsql recursion
  In-Reply-To: <1053655182.279.28.camel@jester>

* 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