PostgreSQL、pgsql为表添加列或判断列存不存在再添加列的方法
程序员文章站
2022-03-23 14:21:02
1.通用方法:
eg:
do $$
begin
begin
alter table dingtalk_corp_info add colum...
1.通用方法:
eg:
do $$ begin begin alter table dingtalk_corp_info add column admin_id text; exception when duplicate_column then raise notice 'column admin_id already exists in dingtalk_corp_info.'; end; end; $$;
2.pgsql 9.6+:
eg:
alter table dingtalk_corp_info add column if not exists admin_id text;
3.直接添加
eg:
alter table dingtalk_corp_info add column admin_id text;
上一篇: sql模糊查询使用介绍