Обсуждение: select as

Поиск
Список
Период
Сортировка

select as

От
Bambero
Дата:
Hello

Is there any easy way to select all fields from table (*) but the result
should looks like this:

   1|    2|    3
----+-----+------
asas| asd | dasd
ada | ads | dasa

Column name should be a number of column.

I don't know what fields are in the table so:

select fieldname as 1, fieldname2 as 2

is useless.

Bambero

Re: select as

От
Michael Fuhr
Дата:
On Thu, Dec 23, 2004 at 06:37:14PM +0000, Bambero wrote:

> Is there any easy way to select all fields from table (*) but the result
> should looks like this:
>
>   1|    2|    3
> ----+-----+------
> asas| asd | dasd
> ada | ads | dasa
>
> Column name should be a number of column.

Why do you need to do this?  Anyway, if you're making queries with
an interface that can fetch rows as an array, then you could display
column numbers based on their position in the array.

> I don't know what fields are in the table so:
>
> select fieldname as 1, fieldname2 as 2
>
> is useless.

What problem are you trying to solve?  Why are you querying a table
when you don't know what fields it has?  Are you building a generic
interface for querying any table?  If so, then you can get column
positions and types by examining the system catalogs.  See the
"System Catalogs" and "The Information Schema" chapters in the
PostgreSQL documentation (Information Schema is available in 7.4
and later).

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

Re: select as

От
Greg Stark
Дата:
Bambero <bambero@tlen.pl> writes:

> I don't know what fields are in the table so:
>
> select fieldname as 1, fieldname2 as 2
>
> is useless.

slo=> create table x (foo text,bar text,baz text);
CREATE TABLE
slo=> select * from (select * from x) as x ("1","2","3");
 1 | 2 | 3
---+---+---
(0 rows)

--
greg