Received: from localhost (maia-2.hub.org [200.46.204.187]) by postgresql.org (Postfix) with ESMTP id B078E9FA6AC for ; Wed, 2 May 2007 16:26:29 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.187]) (amavisd-maia, port 10024) with ESMTP id 67368-05 for ; Wed, 2 May 2007 16:26:24 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from insiderscore.com (mail01.insiderscore.com [69.84.139.233]) by postgresql.org (Postfix) with ESMTP id 7938B9FA1C0 for ; Wed, 2 May 2007 16:26:26 -0300 (ADT) Received: from [192.168.1.4] (mail01.insiderscore.com [69.84.139.233]) by insiderscore.com (Postfix) with ESMTP id 0065E5B8003; Wed, 2 May 2007 15:26:24 -0400 (EDT) Subject: Re: Possible to access value in RECORD without knowing column name? From: Richard Albright To: Collin Peters Cc: pgsql-sql@postgresql.org In-Reply-To: References: Content-Type: text/plain Date: Wed, 02 May 2007 15:26:23 -0400 Message-Id: <1178133983.26840.5.camel@MSI1036> Mime-Version: 1.0 X-Mailer: Evolution 2.10.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200705/8 X-Sequence-Number: 28289 my_column = 'foo' sql = 'select col1, col2, ' || my_column || ' as bar from mytable; for myrecord in execute sql loop myvariable = myrecord.bar end loop; On Wed, 2007-05-02 at 12:17 -0700, Collin Peters wrote: > In plpgsl, if I have a RECORD variable that is populated via some > dynamic SQL, is it possible to access the columns in that RECORD > object without knowing the column names? I.e. Can I grab whatever > value is the 3rd column? > > random_colname = 'foobar'; > sql = 'SELECT col1, col2, ' || random_colname || ' FROM table'; > > FOR mviews IN EXECUTE sql LOOP > --possible to access 3rd column of mviews? something like mviews[3]? > END LOOP; > > Regards, > Collin > > ---------------------------(end of broadcast)--------------------------- > TIP 1: if posting/reading through Usenet, please send an appropriate > subscribe-nomail command to majordomo@postgresql.org so that your > message can get through to the mailing list cleanly -- Rick Albright Senior Quantitative Analyst Indie Research, LLC 254 Witherspoon Street Princeton, NJ 08542 (609)497-1030 ralbright@insiderscore.com