@ -10,4 +10,8 @@ where relkind = 'r' and relname like 'j%_r' and relname not like 'pg_%' and rel
-- 设置默认值
select 'DO $$ BEGIN BEGIN ALTER TABLE '||relname||' ALTER COLUMN recordyear SET DEFAULT 2020; EXCEPTION WHEN duplicate_column THEN RAISE NOTICE ''column recordyear already exists''; END; END;$$;' as tabname from pg_class c
where relkind = 'r' and relname like 'j%_r' and relname not like 'pg_%' and relname not like 'sql_%' order by relname;
where relkind = 'r' and relname like 'j%_r' and relname not like 'pg_%' and relname not like 'sql_%' order by relname;
-- 删除默认值
ALTER TABLE table_name ALTER COLUMN column_name DROP DEFAULT;