X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 58CEB9FA61D for ; Fri, 21 Jul 2006 17:19:21 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 99574-06 for ; Fri, 21 Jul 2006 20:19:18 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from Saturn.acrodex.com (saturn.acrodex.com [139.142.184.3]) by postgresql.org (Postfix) with ESMTP id 177DF9FA3B3 for ; Fri, 21 Jul 2006 16:14:46 -0300 (ADT) X-MimeOLE: Produced By Microsoft Exchange V6.5.7226.0 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Subject: CREATE TABLE AS inside of a function Date: Fri, 21 Jul 2006 13:14:29 -0600 Message-ID: <6EA72AC41F81D242A38AAF505523A94D022DF6@kappa.acrodex.net> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: CREATE TABLE AS inside of a function Thread-Index: Acas+eOdEe9HJDBkS3yjyDCbDMW7Kw== From: "Kevin Nikiforuk" To: X-imss-version: 2.041 X-imss-result: Passed X-imss-scores: Clean:9.37986 C:2 M:3 S:5 R:5 X-imss-settings: Baseline:1 C:1 M:1 S:1 R:1 (0.0000 0.0000) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200607/282 X-Sequence-Number: 25856 So now that I've got my loops working, on to my next newbie question. = I've created my function and in it, I want to loop through the results = of a select and for each value of my loop counter, I want to create a = new table, but I can't figure out how to use a variable in the name of = the new table, see below. =20 CREATE OR REPLACE FUNCTION rgio() RETURNS INTEGER as $$ DECLARE=20 lv RECORD; =20 BEGIN FOR lv IN SELECT DISTINCT rg FROM ldevrg LOOP CREATE TABLE rgio_$lv AS=20 SELECT ldev=20 FROM ldevrg=20 WHERE rg=3D'$lv'; END LOOP; RETURN 1; END; $$ LANGUAGE plpgsql; Thanks, Kevin