【发布时间】:2020-04-28 19:00:31
【问题描述】:
我有一个stats 表格,比如
name | age | sound
------------------
m | 5 | a
a | 3 | c
c | 5 | d
f | 1 | j
d | 6 | r
c | 55 | d
我添加了一个名为appearance的列
ALTER TABLE stats
ADD appearance INTEGER DEFAULT case
when age > 4 then 'red'
when name = f then 'blue'
end
并获得如下表格:
name | age | sound | appearance
--------------------------------
m | 5 | a | red
a | 3 | c | <null>
c | 5 | d | red
f | 1 | j | blue
d | 6 | r | red
c | 55 | d | red
然后,我想添加另一列,名为flavor
ALTER TABLE stats
ADD flavor varchar(20) case
WHEN appearance = 'red' THEN 'apple'
WHEN appearance = 'blue' THEN 'blueberry'
END
但我一直收到错误消息:
[Vertica][VJDBC](7344) ROLLBACK: default expressions may not refer to other columns with default expressions
如何从我创建的第一列创建第二列?
【问题讨论】:
-
您最好使用“派生”列的视图。这些值仅在数据加载到表中时设置,因此不能保证派生值是最新的。