Re: Recursive SETOF function

From: Pierre-Frédéric Caillaud <lists(at)boutiquenumerique(dot)com>
To: "Richard Rowell" <richard(at)bowmansystems(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Recursive SETOF function
Date: 2004-11-22 23:19:17
Message-ID: opshv22fo2cq72hf@musicbox
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


> SELECT INTO cid count(*) FROM providers WHERE uid =child_provider;

Hey, hey.
Better :

SELECT blablah FROM providers WHERE uid = child_provider LIMIT 1;
IF NOT FOUND THEN exit with error ELSE do your stuff

Why scan more than 1 row when you just need existence ?
Or :

SELECT INTO cid parent_id FROM providers WHERE uid=cid;
WHILE FOUND
RETURN NEXT cid;
SELECT INTO cid parent_id FROM providers WHERE uid=cid;
END;

Not sure about the While syntax but you get the idea.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message sreejith s 2004-11-23 04:21:12 Image Insert Postgresql DB
Previous Message Richard Rowell 2004-11-22 20:21:00 Re: [postgres] Re: Recursive SETOF function