Skip to content
Advertisement

Accessing PostgreSQL Fields via Indexing

Is there a way in PostgreSQL to access fields without explicitly providing the column name? For example, instead of the statement:

select (col1,col2,col3,...col42) from foo_table;

there’s a (possible) alternative of:

select (1:42) from foo_table;

Advertisement

Answer

There is no such syntax in Postgres’ SQL.

You could always resort to having code that dynamically constructs the query for you before executing it, but that’s about as good as it will get.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement