更改postgres类型的sql脚本;作为「;不存在
我想编写postgres alter脚本,在现有表中添加一列 我尝试过这个脚本,它在mssqlserver和oracle中也能正常工作 但是我在postgres sql中遇到了错误 错误:类型“AS”不存在 第1行:alter table employee添加唯一列集合(在更改postgres类型的sql脚本;作为「;不存在,sql,postgresql,Sql,Postgresql,我想编写postgres alter脚本,在现有表中添加一列 我尝试过这个脚本,它在mssqlserver和oracle中也能正常工作 但是我在postgres sql中遇到了错误 错误:类型“AS”不存在 第1行:alter table employee添加唯一列集合(在 ALTER TABLE employee add unique_colum AS (case when flag = 'n' then ids else name end); 标志和标识是现有的列,我想再添加一个名为唯一列
ALTER TABLE employee add unique_colum AS (case when flag = 'n' then ids else name end);
标志和标识是现有的列,我想再添加一个名为唯一列
和现有表中新列的值。Postgres不支持计算列。您正在Postgres中使用SQL Server语法 使用视图可以获得类似的功能:
create view v_employee as
select e.*, (case when flag = 'n' then ids else name end) as unique_column
from employee;
postgres中的错误应仅标记为postgres。@RaviKumar…您可以在postgres中的表达式上创建唯一索引。@GordonLinoff…您是对的,但我添加的新列应具有不同于多个基于case语句的列的值。。。