Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id 52BDB9FB502 for ; Sun, 11 Feb 2007 17:47:02 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-new, port 10024) with ESMTP id 71564-03 for ; Sun, 11 Feb 2007 17:46:52 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from bay0-omc3-s12.bay0.hotmail.com (bay0-omc3-s12.bay0.hotmail.com [65.54.246.212]) by postgresql.org (Postfix) with ESMTP id 7119F9FB51B for ; Sun, 11 Feb 2007 17:46:55 -0400 (AST) Received: from hotmail.com ([207.46.10.243]) by bay0-omc3-s12.bay0.hotmail.com with Microsoft SMTPSVC(6.0.3790.2668); Sun, 11 Feb 2007 13:46:54 -0800 Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Sun, 11 Feb 2007 13:46:54 -0800 Message-ID: Received: from 207.46.10.254 by by122fd.bay122.hotmail.msn.com with HTTP; Sun, 11 Feb 2007 21:46:51 GMT X-Originating-IP: [213.129.232.56] X-Originating-Email: [seppwimmer@hotmail.com] X-Sender: seppwimmer@hotmail.com In-Reply-To: <1f30b80c0702111305m7c04ffe4hbb58d780561eb606@mail.gmail.com> From: "Robert Wimmer" To: immaad@gmail.com, pgsql-interfaces@postgresql.org Subject: Re: temporary table / recursion Date: Sun, 11 Feb 2007 21:46:51 +0000 Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed X-OriginalArrivalTime: 11 Feb 2007 21:46:54.0207 (UTC) FILETIME=[252230F0:01C74E26] X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=1.731 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, DNS_FROM_RFC_POST, MSGID_FROM_MTA_HEADER, SPF_PASS, UPPERCASE_25_50 X-Spam-Level: * X-Archive-Number: 200702/14 X-Sequence-Number: 6434 dear imad, thank you very much for your help and your patience. after "executing" really every statement it works. even the FOR tmp IN statement has to be "executed" sepp *** solution *** CREATE FUNCTION recurs.scan(p_start INTEGER) RETURNS SETOF recurs.tree AS $$ DECLARE tmp RECORD; BEGIN EXECUTE 'CREATE TEMP TABLE recurs_temp (id INT, parent_id INT, label TEXT)'; EXECUTE 'INSERT INTO recurs_temp SELECT * FROM recurs.tree WHERE id = ' || p_start; -- first node EXECUTE recurs.walk(p_start); FOR tmp IN EXECUTE 'SELECT * FROM recurs_temp' LOOP RETURN NEXT tmp; END LOOP; EXECUTE 'DROP TABLE recurs_temp'; RETURN; END; $$ LANGUAGE plpgsql; >From: imad >To: "Robert Wimmer" >CC: pgsql-interfaces@postgresql.org >Subject: Re: [INTERFACES] temporary table / recursion >Date: Mon, 12 Feb 2007 02:05:57 +0500 > >Your INSERT statement is still missing EXECUTE command :-) > >--Imad >www.EnterpriseDB.com > >On 2/12/07, Robert Wimmer wrote: >> >> >Not like that, use the execute command inside your function. >> >Here is the description and example. >> >http://www.postgresql.org/docs/8.0/static/plpgsql-statements.html >> > >> >>that was what I tried before the PREPARE EXECUTE example and it did not >>work. >>so i will try it again >> >>*** snippet *** >> >>CREATE FUNCTION recurs.scan(p_start INTEGER) RETURNS SETOF recurs.tree AS >>$$ >>DECLARE tmp RECORD; >>BEGIN >> >> EXECUTE 'CREATE TEMP TABLE recurs_temp (id INT, parent_id INT, label >>TEXT)'; >> >> INSERT INTO recurs_temp SELECT * FROM recurs.tree WHERE id = p_start; >>-- >>first node >> EXECUTE recurs.walk(p_start); -- create tree >> FOR tmp IN SELECT * FROM recurs_temp LOOP RETURN NEXT tmp; END LOOP; >> >> EXECUTE 'DROP TABLE recurs_temp'; >> >> RETURN; >> >>END; $$ >>LANGUAGE plpgsql; >> >>**** >> >>and the output ... >> >>**** >> >>recurs=# SELECT * FROM recurs.scan(1); >>id | parent_id | label >>----+-----------+----------- >> 1 | | 1 >> 4 | 2 | 1.1.1 >> 5 | 2 | 1.1.2 >> 6 | 2 | 1.1.3 >> 7 | 2 | 1.1.4 >> 8 | 2 | 1.1.5 >>11 | 10 | 1.1.6.2 >>13 | 12 | 1.1.6.3.1 >>12 | 10 | 1.1.6.3 >>10 | 9 | 1.1.6.1 >> 9 | 2 | 1.1.6 >> 2 | 1 | 1.1 >>14 | 3 | 1.2.1 >>15 | 3 | 1.2.2 >>16 | 3 | 1.2.3 >> 3 | 1 | 1.2 >>(16 rows) >> >>recurs=# \dt >>No relations found. >>recurs=# SELECT * FROM recurs.scan(1); >>ERROR: relation with OID 2084590 does not exist >>KONTEXT: SQL statement "INSERT INTO recurs_temp SELECT * FROM recurs.tree >>WHERE id = $1 " >>PL/pgSQL function "scan" line 6 at SQL statement >>recurs=# \dt >>No relations found. >> >>**** >> >> >>so i dont know what went wrong now ... >> >>i am using Postgres 8.0.3 on Windows XP >> >>nevertheless thanx for your help >> >> > >> >--Imad >> >www.EnterpriseDB.com >> > >> >---------------------------(end of broadcast)--------------------------- >> >TIP 6: explain analyze is your friend >> >>_________________________________________________________________ >>Die MSN Homepage liefert Ihnen alle Infos zu Ihren Lieblingsthemen. >>http://at.msn.com/ >> >> _________________________________________________________________ Nur die MSN Suche sorgt bei einer Web-Recherche für optimale Ergebnisse. http://search.msn.at/