在 Redshift 中创建视图时选择列名

Choosing the name of a column when creating a view in Redshift

我正在尝试创建一个视图,其中包含一个带有代码列表的列。这是我目前拥有的 SQL 代码:

DROP VIEW IF EXISTS myview;
CREATE OR REPLACE VIEW myview as
SELECT 'code1'
UNION
SELECT 'code2'
UNION
SELECT 'code3'

这将创建一个包含此列的视图:

?列?
code1
code2
code3

如您所见,列名是“?column?”我想将其更改为我选择的名称。我试过查看 Redshift documentation,它说您可以指定列名,但我不确定什么是正确的语法,因为他们没有给出任何示例。

只需添加一个带有列名称的别名

CREATE OR REPLACE VIEW logs.myview as
SELECT 'code1' as my_column
UNION
SELECT 'code2'
UNION
SELECT 'code3';