Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 23CE04760D4 for ; Thu, 7 Nov 2002 16:27:32 -0500 (EST) Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (Postfix) with ESMTP id 2B4C5476D98 for ; Thu, 7 Nov 2002 16:27:27 -0500 (EST) Received: from [216.135.165.74] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.5.9) with HTTP id 1816701; Thu, 07 Nov 2002 13:30:20 -0800 From: "Josh Berkus" Subject: Re: PLpgSQL FOR IN EXECUTE question To: Christoph Haller , pgsql-sql@postgresql.org X-Mailer: CommuniGate Pro Web Mailer v.3.5.9 Date: Thu, 07 Nov 2002 13:30:20 -0800 Message-ID: In-Reply-To: <3DCA7A2E.6DD4CABE@rodos.fzk.de> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/121 X-Sequence-Number: 10263 Chris, > FOR this_record IN > EXECUTE ''SELECT '' > || quote_ident($1) > || ''FROM '' > || quote_ident($2) > LOOP > list := list || '', '' || this_record.$1 ; > END LOOP; > > As expected, accessing a field via this_record.$1 > does not work. > Can it be done otherwise? Yes. Alias the columns: FOR this_record IN EXECUTE ''SELECT '' || quote_ident($1) || '' AS col1 FROM '' || quote_ident($2) || '' AS col2'' LOOP list := list || '', '' || this_record.col1 ; END LOOP;