Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 407219066CF for ; Thu, 7 Jun 2012 20:17:50 -0300 (ADT) Received: from [76.14.161.106] (helo=newserver.jfcomputer.com) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Sclxd-0000To-8K for pgsql-sql@postgresql.org; Thu, 07 Jun 2012 23:17:49 +0000 Received: from localhost (unknown [127.0.0.1]) by newserver.jfcomputer.com (Postfix) with ESMTP id 2C3E912350 for ; Thu, 7 Jun 2012 23:17:35 +0000 (UTC) X-Virus-Scanned: amavisd-new at site Received: from newserver.jfcomputer.com ([127.0.0.1]) by localhost (linux-jfp8.site [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id g+eE3PzTuDhc for ; Thu, 7 Jun 2012 16:17:34 -0700 (PDT) Received: from [192.168.1.114] (unknown [192.168.1.254]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: johnf@jfcomputer.com) by newserver.jfcomputer.com (Postfix) with ESMTPSA id 7F61F555A for ; Thu, 7 Jun 2012 16:17:34 -0700 (PDT) Message-ID: <4FD1368E.5000304@jfcomputer.com> Date: Thu, 07 Jun 2012 16:17:34 -0700 From: John Fabiani Reply-To: johnf@jfcomputer.com User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:12.0) Gecko/20120421 Thunderbird/12.0 MIME-Version: 1.0 To: "pgsql-sql@postgresql.org" Subject: using ordinal_position Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Host-Lookup-Failed: Reverse DNS lookup failed for 76.14.161.106 (failed) X-Pg-Spam-Score: 1.6 (+) X-Archive-Number: 201206/25 X-Sequence-Number: 36679 I'm attempting to retrieve data using a select statement without knowing the column names. I know the ordinal position but not the name of the column (happens to be a date::text and I have 13 fields). Below provides the name of the column in position 3: select column_name from (select column_name::text, ordinal_position from information_schema.columns where table_name='wk_test') as foo where ordinal_position = 3; But how can I use the above as a column name in a normal select statement. Unlike other databases I just can't use ordinal position in the select statement - RIGHT??? Johnf