Re: Alias name from subquery - Mailing list pgsql-general

From Felix Homann
Subject Re: Alias name from subquery
Date
Msg-id 48E237DD.5050603@onlinehome.de
Whole thread Raw
In response to Alias name from subquery  (Felix Homann <fexpop@onlinehome.de>)
Responses Re: Alias name from subquery
List 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)




pgsql-general by date:

Previous
From: "Sean Davis"
Date:
Subject: MySQL to Postgresql schema conversion
Next
From: Raymond O'Donnell
Date:
Subject: Re: Alias name from subquery