From ab69336254c570928454386a6297dbf64282ff50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=B5=B7?= <10402852@qq.com> Date: Mon, 12 Apr 2021 10:03:02 +0800 Subject: [PATCH] 'commit' --- Document/PG增加列.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Document/PG增加列.txt b/Document/PG增加列.txt index 473d0603..6bc5f357 100644 --- a/Document/PG增加列.txt +++ b/Document/PG增加列.txt @@ -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; \ No newline at end of file +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; \ No newline at end of file