Alter列使其成为派生的列
我正在学习PostgreSQL,我想知道可以在表中添加派生列,然后在另一行上更改它,我尝试了不同的方式,但是我找不到正确的语法。
出于某种原因,似乎这项演习希望在两行上想要它,但是我目前只能做到这一点。
-- 1) Add an attribute Taxes to table Payment
ALTER TABLE Payment
ADD Taxes real;
-- 2) Set the derived attribute taxes as 12% of PaySlip
ALTER TABLE Payment
ALTER COLUMN Taxes AS (0.12*Payment.PaySlip);
I'm learning PostgreSQL and I'm wondering is it possible to add a derived column to a table then ALTER it on a another line, I've tried different ways but I can't find the correct Syntax for it.
For some reason its seems as if the exercise wants it on two lines, but I can only do it on one at the moment.
-- 1) Add an attribute Taxes to table Payment
ALTER TABLE Payment
ADD Taxes real;
-- 2) Set the derived attribute taxes as 12% of PaySlip
ALTER TABLE Payment
ALTER COLUMN Taxes AS (0.12*Payment.PaySlip);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试使用 a>
如果此列存在在您的表中,我们可能需要在创建它之前将其删除。
由于该文档可能不支持 a>带有
生成的
You can try to use
Generated Columns
If this column exists in your table, we might need to drop it before creating it.
Due to the document might not support
ALTER COLUMN
withGENERATED
sqlfiddle