Skip site navigation (1) Skip section navigation (2)

using ordinal_position

From: John Fabiani <johnf(at)jfcomputer(dot)com>
To: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: using ordinal_position
Date: 2012-06-07 23:17:34
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
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???



pgsql-sql by date

Next:From: David JohnstonDate: 2012-06-07 23:32:52
Subject: Re: using ordinal_position
Previous:From: David JohnstonDate: 2012-06-06 15:27:40
Subject: Re: defaults in a function

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group