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


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();

猜你喜欢

转载自www.cnblogs.com/19940330a/p/9079339.html