Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 48A90477484 for ; Wed, 29 Jan 2003 05:12:49 -0500 (EST) Received: from resu1.ulb.ac.be (resu1.ulb.ac.be [164.15.59.200]) by postgresql.org (Postfix) with ESMTP id 4A5DE47738A for ; Wed, 29 Jan 2003 04:21:27 -0500 (EST) Received: from mach.vub.ac.be (mach.ulb.ac.be [164.15.128.3]) by resu1.ulb.ac.be (8.8.8/3.17.1.ap (resu)) id KAA24610; Wed, 29 Jan 2003 10:19:41 +0100 (MET) for Received: from ulb.ac.be (geog-pc35.ulb.ac.be [164.15.134.155]) by mach.vub.ac.be (8.9.3/3.13.3.ap (mach)) id KAA13100; Wed, 29 Jan 2003 10:21:26 +0100 (MET) for Received: from 164.15.128.4 (SquirrelMail authenticated user mlennert) by http://moritz.homelinux.org with HTTP; Wed, 29 Jan 2003 10:21:20 +0100 (CET) Message-ID: <51767.164.15.128.4.1043832080.squirrel@http://moritz.homelinux.org> Date: Wed, 29 Jan 2003 10:21:20 +0100 (CET) Subject: plpgsql: return results of a dynamic query From: "Moritz Lennert" To: pgsql-sql@postgresql.org Reply-To: mlennert@club.worldonline.be X-Mailer: SquirrelMail (version 1.3.2) MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-1 X-Priority: 3 Importance: Normal X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200301/481 X-Sequence-Number: 11346 Hello, I'am a complete newbie to plpgsql, so if this information is explained somewhere where I haven't looked, yet, please point me to the doc... (I didn't find the answer in the PostgreSQL Programmer's Guide.) I use PG 7.3.1. I'm trying to retrieve a row count from several tables (40) and would like to create a function that does this automatically for the 40 and displays the results. So, I loop through the tables: DECLARE obj RECORD; BEGIN FOR obj IN SELECT relname AS name FROM pg_class WHERE relkind IN ('r') AND relname like '%_random' AND relname != 'tout_random' LOOP then I need to do the select count for each table in the lines of SELECT count(t1.id) AS total FROM || obj.name || AS t1 JOIN tout_random AS t2 ON t1.id=t2.id WHERE t2.ok=TRUE; and return the result of each of these select counts. Could someone indicate how to return the results of these queries ? Am I right that in order to do this dynamic query, I have to use an EXECUTE statement ? Can I return the results of an EXECUTE statement ? Thanks, Moritz