Re: Alias name from subquery

From: Felix Homann <fexpop(at)onlinehome(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Alias name from subquery
Date: 2008-09-30 14:29:49
Message-ID: 48E237DD.5050603@onlinehome.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Jeffrey,

Thanks for your quick response!

Hoover, Jeffrey wrote:
>
> select (SELECT name from colnames WHERE id=1) as entry from entries;
>

I think, I should have been a bit clearer in what I need:

I've got two tables, colnames and entries:

test=# SELECT * from colnames;
id | name
----+------
1 | col1
(1 row)

test=# SELECT entry from entries;
entry
--------
first
second
third
(3 rows)

I would like to get the column name "entry" replaced by an alias "col1",
just like this:

test=# SELECT entry as col1 from entries;
col1
--------
first
second
third
(3 rows)

_But_, I don't want to give the alias explicitely, instead it should be
taken from a second table 'colnames', i.e. something like the line I
sent in my initial mail. Any idea?

Thanks again,

Felix

BTW, here's what I get from your command:

test=# select (SELECT name from colnames WHERE id=1) as entry from entries;
entry
-------
col1
col1
col1
(3 rows)

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Raymond O'Donnell 2008-09-30 14:32:09 Re: Alias name from subquery
Previous Message Sean Davis 2008-09-30 14:08:14 MySQL to Postgresql schema conversion