sql - 将生成的列添加到现有表 Postgres
问题描述
我正在尝试使用此脚本将生成的列添加到现有表中。
alter table Asset_Store add column
md5_hash VARCHAR(100) GENERATED ALWAYS AS
(CAST(UPPER(
case
when OR_ID is not null then MD5(cast(OR_ID as varchar(100)))
when Asset_ID is not null then MD5(Asset_ID)
else null
end
) as VARCHAR(100)))
STORED
;
但我收到一个错误:
SQL Error [42601]: ERROR: syntax error at or near "("
Position: 88
ERROR: syntax error at or near "("
Position: 88
ERROR: syntax error at or near "("
Position: 88
问题是什么?我不明白。
在我的 Asset_Store 表的架构中,列
OR_ID 是int
,Asset_ID 是varchar(100)
。
我想它需要一个稍微不同的语法......但什么是正确的语法?
解决方案
你的语法是正确的。您的 PostgreSQL 版本显然不是。
在版本 12 中:
create table asset_store(or_id text, asset_id text);
alter table Asset_Store add column
md5_hash VARCHAR(100) GENERATED ALWAYS AS
(CAST(UPPER(
case
when OR_ID is not null then MD5(cast(OR_ID as varchar(100)))
when Asset_ID is not null then MD5(Asset_ID)
else null
end
) as VARCHAR(100)))
STORED
;
ALTER TABLE Time: 17.678 ms
推荐阅读
- ruby-on-rails - 有条件地向哈希列表添加更多键
- python - 从 href html PHP 或 js 启动记事本或 python 或批处理(后台应用程序或脚本)
- laravel - Laravel vue下载的PDF文件未加载
- c++ - return (int32_t& 1u) ^ 1u 是什么意思?
- pine-script - 如何绘制较高时间范围的最高价格并在较低时间范围图表上查看
- python-asyncio - Pytest 一个调用异步协程的函数
- ubuntu-16.04 - 关于 ethtool 收发器的类型,“外部”和“内部”有什么区别?
- javascript - chartjs中图表区域的背景颜色不起作用
- c# - 检测非公历日期格式
- scenebuilder - SceneBuilder 16 中的资源(捆绑包)