On naming attributes in a WITH clause

From: AM <agentm(at)themactionfaction(dot)com>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: On naming attributes in a WITH clause
Date: 2011-11-23 18:46:07
Message-ID: BD51EF04-406C-44D2-8391-805E73DB1177@themactionfaction.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Johnston 2011-11-23 18:51:43 Re: On naming attributes in a WITH clause
Previous Message Rich Shepard 2011-11-23 18:33:03 Blank Numeric Column For INSERT