Re: select column by position - Mailing list pgsql-sql

From Chester Kustarz
Subject Re: select column by position
Date
Msg-id Pine.BSO.4.44.0409241653320.17616-100000@detroit.arbor.net
Whole thread Raw
In response to select column by position  ("Jennifer Lee" <jlee@scri.sari.ac.uk>)
List 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:

http://www.postgresql.org/docs/7.4/interactive/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN

Documentation about what is stored in the system catalogs can be found:
http://www.postgresql.org/docs/7.4/interactive/catalogs.html




pgsql-sql by date:

Previous
From: Greg Stark
Date:
Subject: Re: [GENERAL] need ``row number``
Next
From: Szálka Tamás
Date:
Subject: plpgsql - accessing fields of record type