在
DO语句中循环,例如:
b=# create table a (a int primary key, b int unique);CREATE TABLEb=# create table b (a int references a(a), b int references a(b));CREATE TABLEb=# do$$declare r record;beginfor r in (select constraint_name from information_schema.table_constraints where table_schema = 'public' and table_name='b') loop raise info '%','dropping '||r.constraint_name; execute CONCAt('ALTER TABLE "public"."b" DROP ConSTRAINT '||r.constraint_name);end loop;end;$$;INFO: dropping b_a_fkeyINFO: dropping b_b_fkeyDO


