logo       

Re: temporary table / recursion: msg#00011

Subject: Re: temporary table / recursion

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/


---------------------------(end of broadcast)---------------------------
TIP 9: In versions below 8.0, the planner will ignore your desire to
      choose an index scan if your joining column's datatypes do not
      match



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
boot-loaders.gr...    php.pear.genera...    debugging.valgr...    kde.redhat.user...    text.xml.xsl.ge...    culture.languag...    hardware.microc...    java.servicemix...    redhat.release....    web.zope.plone....    user-groups.lin...    opendarwin.webk...    video.mjpeg.use...    sysutils.bcfg2....    encryption.gpg....    lx-office.devel...    xfree86.forum/2...    mail.mutt.devel...    acpi.devel/2003...    qnx.openqnx.dev...    network.irc.irs...    freebsd.devel.m...   
Home | blog view | USPTO Patent Archive | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe