Re: column number instead of column name

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: First Last <y2kdis(at)atenista(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: column number instead of column name
Date: 2006-01-21 05:22:46
Message-ID: 20060121052246.GA20004@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message David Chapman 2006-01-22 02:39:28 msysconf error
Previous Message First Last 2006-01-20 08:24:37 column number instead of column name