From 5e53a5bb3291d85d2bf01909b0681b994f448d10 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Mon, 17 Sep 2007 14:27:40 +0000 Subject: [PATCH] store full fkey sql in table --- sql/londiste/functions/londiste.find_table_fkeys.sql | 5 ++++- .../functions/londiste.subscriber_fkeys_funcs.sql | 10 +++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/sql/londiste/functions/londiste.find_table_fkeys.sql b/sql/londiste/functions/londiste.find_table_fkeys.sql index ce02ce72..2a2cc560 100644 --- a/sql/londiste/functions/londiste.find_table_fkeys.sql +++ b/sql/londiste/functions/londiste.find_table_fkeys.sql @@ -9,7 +9,10 @@ begin for fkey in select n1.nspname || '.' || t1.relname as from_table, n2.nspname || '.' || t2.relname as to_table, - conname::text as fkey_name, pg_get_constraintdef(c.oid) as fkey_def + conname::text as fkey_name, + 'alter table only ' || quote_ident(n1.nspname) || '.' || quote_ident(t1.relname) + || ' add constraint ' || quote_ident(fkey.fkey_name) || ' ' || pg_get_constraintdef(c.oid) + as fkey_def from pg_constraint c, pg_namespace n1, pg_class t1, pg_namespace n2, pg_class t2 where c.contype = 'f' and (c.conrelid = tbl_oid or c.confrelid = tbl_oid) and t1.oid = c.conrelid and n1.oid = t1.relnamespace diff --git a/sql/londiste/functions/londiste.subscriber_fkeys_funcs.sql b/sql/londiste/functions/londiste.subscriber_fkeys_funcs.sql index cad1ebaf..3eda8d60 100644 --- a/sql/londiste/functions/londiste.subscriber_fkeys_funcs.sql +++ b/sql/londiste/functions/londiste.subscriber_fkeys_funcs.sql @@ -53,12 +53,13 @@ begin where fkey_name = i_fkey_name and from_table = i_from_table; if not found then - return 1; + return 0; end if; insert into londiste.subscriber_pending_fkeys values (fkey.from_table, fkey.to_table, i_fkey_name, fkey.fkey_def); - execute 'alter table only ' || fkey.from_table || ' drop constraint ' || i_fkey_name || ';'; + execute 'alter table only ' || londiste.quote_fqname(fkey.from_table) + || ' drop constraint ' || quote_ident(i_fkey_name); return 1; end; @@ -75,13 +76,12 @@ begin where fkey_name = i_fkey_name and from_table = i_from_table; if not found then - return 1; + return 0; end if; delete from londiste.subscriber_pending_fkeys where fkey_name = fkey.fkey_name; - execute 'alter table only ' || fkey.from_table || ' add constraint ' - || fkey.fkey_name || ' ' || fkey.fkey_def || ';'; + execute fkey.fkey_def; return 1; end; -- 2.39.5