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 14ECBD9A91 for ; Wed, 28 Sep 2005 13:52:46 -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 43913-06 for ; Wed, 28 Sep 2005 16:52:42 +0000 (GMT) Received: from ls405.htnet.hr (ls405.htnet.hr [195.29.150.97]) by svr1.postgresql.org (Postfix) with ESMTP id 9E3A7D9A84 for ; Wed, 28 Sep 2005 13:52:40 -0300 (ADT) Received: from ls422.t-com.hr (ls422.t-com.hr [195.29.150.237]) by ls405.htnet.hr (0.0.0/8.12.10) with ESMTP id j8SGqaWt006235 for ; Wed, 28 Sep 2005 18:52:38 +0200 Received: from ls422.t-com.hr (localhost.localdomain [127.0.0.1]) by ls422.t-com.hr (Qmlai) with ESMTP id EE3CF988043 for ; Wed, 28 Sep 2005 18:52:38 +0200 (CEST) X-Envelope-Sender: mario.splivalo@mobart.hr Received: from ls422.t-com.hr (localhost.localdomain [127.0.0.1]) by ls422.t-com.hr (Qmlai) with ESMTP id EBCA2988042 for ; Wed, 28 Sep 2005 18:52:38 +0200 (CEST) Received: from 83-131-24-122.adsl.net.t-com.hr (83-131-24-122.adsl.net.t-com.hr [83.131.24.122]) by ls422.t-com.hr (Qmlai) with ESMTP id 7E0608B8084 for ; Wed, 28 Sep 2005 18:52:38 +0200 (CEST) Subject: Sending function parametars within EXECUTE ''SELECT... From: Mario Splivalo Reply-To: mario.splivalo@mobart.hr To: pgsql-sql@postgresql.org Content-Type: text/plain Organization: Mob-Art Date: Wed, 28 Sep 2005 18:51:09 +0200 Message-Id: <1127926269.16100.3.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 required=5 tests=[none] X-Spam-Level: X-Archive-Number: 200509/279 X-Sequence-Number: 22826 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.