From: | "David Johnston" <polobo(at)yahoo(dot)com> |
---|---|
To: | "'AM'" <agentm(at)themactionfaction(dot)com>, "'Postgres General'" <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: On naming attributes in a WITH clause |
Date: | 2011-11-23 18:51:43 |
Message-ID: | 07f101ccaa10$f25d4820$d717d860$@yahoo.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
It is described in the "SELECT" documentation "WITH" section but is somewhat
obscure; just add the column names, in (), after the WITH name.
WITH name (col1, col2, col3) AS (
SELECT 1, 2, 3
)
David J.
-----Original Message-----
From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of AM
Sent: Wednesday, November 23, 2011 1:46 PM
To: Postgres General
Subject: [GENERAL] On naming attributes in a WITH clause
Hello,
Is it possible to rename columns in a WITH clause which includes VALUES?
None of the following parse:
WITH map_table AS
(
VALUES ('1','r'),('2','w'),('3','a'),('4','d')
) AS (a,b)
SELECT * FROM map_table;
WITH map_table AS
(
VALUES ('1','r'),('2','w'),('3','a'),('4','d') AS t (a,b)
)
SELECT * FROM map_table;
I would like the map_table columns to have names other than column1 and
column2.
WITH map_table AS
(
VALUES ('1','r'),('2','w'),('3','a'),('4','d')
)
SELECT column1 AS a, column2 AS b FROM map_table;
is close but I would prefer to rename the columns as part of the WITH clause
before the (poorly) named column1 and column2 hit the main query. Is it
possible?
Cheers,
M
--
Sent via pgsql-general mailing list (pgsql-general(at)postgresql(dot)org) To make
changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
From | Date | Subject | |
---|---|---|---|
Next Message | Richard Broersma | 2011-11-23 18:53:35 | Re: Blank Numeric Column For INSERT |
Previous Message | AM | 2011-11-23 18:46:07 | On naming attributes in a WITH clause |