Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TvB1K-00026N-7T for pgsql-sql@arkaria.postgresql.org; Tue, 15 Jan 2013 18:13:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TvB1J-0006uJ-Oj for pgsql-sql@arkaria.postgresql.org; Tue, 15 Jan 2013 18:13:57 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TvB1I-0006uB-PB for pgsql-sql@postgresql.org; Tue, 15 Jan 2013 18:13:56 +0000 Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TvB1F-00035u-LL for pgsql-sql@postgresql.org; Tue, 15 Jan 2013 18:13:56 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1TvA0I-00032C-TG for pgsql-sql@postgresql.org; Tue, 15 Jan 2013 09:08:50 -0800 Date: Tue, 15 Jan 2013 09:08:50 -0800 (PST) From: kgeographer To: pgsql-sql@postgresql.org Message-ID: <1358269730873-5740324.post@n5.nabble.com> In-Reply-To: References: Subject: Re: returning values from dynamic SQL to a variable MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 0.0 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org I have a related problem and tried the PERFORM...EXECUTE pattern suggested but no matter where I put PERFORM I get 'function not found' errors. I want to loop through id values returned by a query and execute another with each i as a parameter. Each subquery will return 6-8 rows. This is a simplified example, in the real app the subquery is doing some aggregation work. Tried many many things including this pattern below and read everything I could find, but no go. Any help appreciated. ++++++++++++++++ create or replace function getRowsA() returns setof record as $$ declare r record; loopy record; i integer; sql text; begin for r in select * from cities loop i := r.id; sql := 'select city,topic,weight from v_doctopic where city = ' || i; EXECUTE sql; return next loopy; end loop; return; end; $$ language 'plpgsql'; select * from getRowsA() AS foo(city int, topic int, weight numeric) ----- karlg -- View this message in context: http://postgresql.1045698.n5.nabble.com/returning-values-from-dynamic-SQL-to-a-variable-tp5723322p5740324.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql