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

Re: select column by position

From: Chester Kustarz <chester(at)arbor(dot)net>
To: Jennifer Lee <jlee(at)scri(dot)sari(dot)ac(dot)uk>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: select column by position
Date: 2004-09-24 21:00:10
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
On Fri, 24 Sep 2004, Jennifer Lee wrote:
> Is there a way to select a column in a table by its position rather than
> the field name? If I understand correctly column position in a table is
> fixed. I've not been able to find anything in the archives or docs to
> indicate that it's possible to select by position.

The general response will be that you don't really want to do this.
You should figure out some other way to query the database that doesn't
rely on column position. For example, dropping and adding columns
with ALTER TABLE command could change their positions.

If you still want to go about it, I suppose it might be possible to
write a PL/pgSQL stored procedure that determines the column name
from the system catalogs, then uses EXECUTE to run the query with
the real column name substituted in the query. See Executing
Dynamic Commands in the documentation:

Documentation about what is stored in the system catalogs can be found:

In response to

pgsql-sql by date

Next:From: Ian HardingDate: 2004-09-24 21:49:56
Subject: Re: [SQL] need ``row number``
Previous:From: Greg StarkDate: 2004-09-24 20:34:47
Subject: Re: [SQL] need ``row number``

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