Re: column number instead of column name - Mailing list pgsql-novice

From Michael Fuhr
Subject Re: column number instead of column name
Date
Msg-id 20060121052246.GA20004@winnie.fuhr.org
Whole thread Raw
In response to column number instead of column name  (First Last <y2kdis@atenista.net>)
List pgsql-novice
On Fri, Jan 20, 2006 at 12:24:37AM -0800, First Last wrote:
> how can i make use of the column number instead of the column
> name when making the select statement?
>
> for instance:
> "SELECT mytable.col[1], mytable.col[2], mytable.col[3], mytable.userid from mytable"

I don't think you can do that in ordinary SQL, but you could query
the system catalogs to get the table structure and generate a list
of column names from that.

> i have several tables and i need to extract the first three columns
> and a known column. the first three columns for the different tables
> vary, but all the tables have the userid column.

Can you tell us a little more about what you're doing?  Some people
would question this design, arguing that a relation's attributes
should be referenced by name and that the order in which they happen
to be stored should be irrelevant and not relied upon.  However,
without knowing what you're doing it's hard to insist that such a
generalization should apply to your case.

--
Michael Fuhr

pgsql-novice by date:

Previous
From: First Last
Date:
Subject: column number instead of column name
Next
From: David Chapman
Date:
Subject: msysconf error