I’m trying to create a view that contains a column with a list of codes. This is the SQL code that I currently have:
x
DROP VIEW IF EXISTS myview;
CREATE OR REPLACE VIEW myview as
SELECT 'code1'
UNION
SELECT 'code2'
UNION
SELECT 'code3'
This creates a view with this column:
?column? |
---|
code1 |
code2 |
code3 |
As you can see the column name is “?column?” and I would like to change it to a name of my choice. I’ve tried looking at the Redshift documentation where it says that you can specify a column name, but I’m not sure what’s the correct syntax since they don’t give any examples.
Advertisement
Answer
just add an alias with the name of column
CREATE OR REPLACE VIEW logs.myview as
SELECT 'code1' as my_column
UNION
SELECT 'code2'
UNION
SELECT 'code3';