Last active
November 3, 2017 01:21
-
-
Save NikolayS/1deefd26fa45c86d5963db070dc07179 to your computer and use it in GitHub Desktop.
make all constraints DEFERRABLE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- use this to make all constraints in "public" schema `deferrable initially immediate` | |
-- (edit schema name if needed) | |
do $$ | |
declare | |
sql text; | |
begin | |
select into sql | |
string_agg( | |
'alter table ' || quote_ident(ns.nspname) || '.' || quote_ident(tb.relname) | |
|| ' alter constraint ' || quote_ident(conname) || ' deferrable initially immediate;' | |
, ' ' | |
) | |
from pg_constraint c | |
join pg_class tb on tb.oid = c.conrelid | |
join pg_namespace ns on ns.oid = tb.relnamespace | |
where c.contype = 'f' and ns.nspname in ('public'); | |
raise notice 'sql: %', sql; | |
execute sql; | |
end; | |
$$ language plpgsql; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment