X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B0950D9AA5 for ; Wed, 28 Sep 2005 13:59:44 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 46077-05 for ; Wed, 28 Sep 2005 16:59:38 +0000 (GMT) Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.116.145.2]) by svr1.postgresql.org (Postfix) with ESMTP id D2381D9AAC for ; Wed, 28 Sep 2005 13:59:37 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id EA2C331F51; Wed, 28 Sep 2005 18:59:37 +0200 (MET DST) From: "codeWarrior" X-Newsgroups: pgsql.sql Subject: Re: Sending function parametars within EXECUTE ''SELECT... Date: Wed, 28 Sep 2005 10:01:23 -0700 Organization: Hub.Org Networking Services Lines: 67 Message-ID: References: <1127926269.16100.3.camel@localhost.localdomain> X-Complaints-To: usenet@news.hub.org X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2670 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670 X-RFC2646: Format=Flowed; Original To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=2.238 required=5 tests=[AWL=-0.026, FORGED_HOTMAIL_RCVD2=1.079, PRIORITY_NO_NAME=1.185] X-Spam-Level: ** X-Archive-Number: 200509/280 X-Sequence-Number: 22827 "Mario Splivalo" wrote in message news:1127926269.16100.3.camel@localhost.localdomain... > I've learned that one can't use temporary tables within the function > unless > EXECUTE'd the SELECTS from that temp table. > > So, I have a function like this: > > CREATE FUNCTION Foo1(int4, int4) RETURNS SETOF myType > AS > ' > DECLARE > aDataId ALIAS FOR $1; > aBid ALIAS FOR $2; > return myType; > rec record; > BEGIN > CREATE TEMP TABLE tmpTbl > AS > SELECT col1, col2 FROM t1 JOIN t2 ON t1.c1 = t2.c3 WHERE t1.c4 = > aDataId; > > FOR rec IN EXECUTE ''SELECT COUNT(col1) AS num FROM tmpTbl WHERE > col2 = aBid'' > LOOP > return.myType = rec.num; > END LOOP; > > RETURN NEXT return; > RETURN; > END > ' language 'pgplsql' > > > Now, when I try to call that function, i get an error that aBid is > unknown > column name. How can I pass the aBid value to the SELECT statement > inside > the EXECUTE? > > I'm using temp table because the tables from where to gather the data > are > huge. If I'd be using views instead, it'd take too much time. I tought > that > storing only a small fraction of the data (1/1000 of the data is put > into > the temp table), and then performing calculations on that temp table > would > be much faster. I just don't know how to pass parameters to the EXECUTE > SELECT. > > Any help here would be appreciated. > > Mike > > P.S. I tried above code on pg8.0.3 and 8.1beta2, with same results. > > > ---------------------------(end of broadcast)--------------------------- > TIP 5: don't forget to increase your free space map settings > FOR rec IN EXECUTE ''SELECT COUNT(col1) AS num FROM tmpTbl WHERE col2 = " || aBid || '' LOOP