码迷,mamicode.com
首页 > 数据库 > 详细

数据库升级,给某张表增加字段,防止重复升级时sql脚本报错

时间:2018-05-23 22:09:09      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:alt   func   and   HERE   pgsql   fun   字段名   table   add   


create or replace function func_add_column() returns int as
$body$
begin
perform * from pg_tables where tablename = ‘表名‘;
if found then
perform * from pg_attribute where attrelid = ‘表名‘::regclass and attname = ‘字段名‘;
if not found then
alter table 表名 add column 字段名 ;
end if;

end if;


return 0 ;
end;
$body$ language plpgsql;
select func_add_column();

数据库升级,给某张表增加字段,防止重复升级时sql脚本报错

标签:alt   func   and   HERE   pgsql   fun   字段名   table   add   

原文地址:https://www.cnblogs.com/19940330a/p/9079339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!