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

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: (view raw, whole thread or download thread mbox)
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

pgsql-novice by date

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

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