Let's say I have the following as a starting point:
select * from (values (1,'a'),(2,'b'))
Is it possible to provide column names to the value columns up-stream, for example something like:
select
col1 AS id,
col2 AS letter
from (
<anonymous values>
)
Or is it basically once you have an anonymous values
clause you cannot name it.
CodePudding user response:
You can use a table alias that also specifies column names:
select *
from (
values (1,'a'),(2,'b')
) as v(id, letter);
CodePudding user response:
use an alias:
select * from (values (1,'a'),(2,'b')) as foo(id,txt);
id | txt
---- -----
1 | a
2 | b
(2 rows)
CodePudding user response:
Absolutely
Just add the column names to the query alias
select q.id, q.col
from (values
(1,'a'),
(2,'b')
) q(id, col)