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
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;
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;