declare
p_tab_id alias for $1;
v_tab_fqname text;
v_tab_oid oid;
begin
-- ----
-- Grab the central configuration lock
-- ----
lock table sl_config_lock;
-- ----
-- Construct the tables fully qualified name and get its oid
-- ----
select slon_quote_brute(PGN.nspname) || '.' ||
slon_quote_brute(PGC.relname),
PGC.oid into v_tab_fqname, v_tab_oid
from sl_table T,
"pg_catalog".pg_class PGC,
"pg_catalog".pg_namespace PGN
where T.tab_id = p_tab_id
and T.tab_reloid = PGC.oid
and PGC.relnamespace = PGN.oid;
if not found then
raise exception 'Slony-I: tableDropKey(): table with ID % not found', p_tab_id;
end if;
-- ----
-- Drop the special serial ID column if the table has it
-- ----
if exists (select true from "pg_catalog".pg_attribute
where attrelid = v_tab_oid
and attname = '_Slony-I_schemadoc_rowID')
then
execute 'lock table ' || v_tab_fqname ||
' in access exclusive mode';
execute 'alter table ' || v_tab_fqname ||
' drop column "_Slony-I_schemadoc_rowID"';
end if;
return p_tab_id;
end; |