store full fkey sql in table
authorMarko Kreen <markokr@gmail.com>
Mon, 17 Sep 2007 14:27:40 +0000 (14:27 +0000)
committerMarko Kreen <markokr@gmail.com>
Mon, 17 Sep 2007 14:27:40 +0000 (14:27 +0000)
sql/londiste/functions/londiste.find_table_fkeys.sql
sql/londiste/functions/londiste.subscriber_fkeys_funcs.sql

index ce02ce72fa9e71877be311728ba7b396dbfc0cd0..2a2cc56015e39f0000f1b1663539508de783aba3 100644 (file)
@@ -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
index cad1ebaf1783c39b1ead3abfa716697356ba72d4..3eda8d604841d1bf7cb845686c0556bfb9db3221 100644 (file)
@@ -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;