Re: select column by position

Поиск
Список
Период
Сортировка
От Chester Kustarz
Тема Re: select column by position
Дата
Msg-id Pine.BSO.4.44.0409241653320.17616-100000@detroit.arbor.net
обсуждение исходный текст
Ответ на select column by position  ("Jennifer Lee" <jlee@scri.sari.ac.uk>)
Список 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 по дате отправления:

Предыдущее
От: Greg Stark
Дата:
Сообщение: Re: [GENERAL] need ``row number``
Следующее
От: Szálka Tamás
Дата:
Сообщение: plpgsql - accessing fields of record type