declare
p_set_id alias for $1;
p_tab_id alias for $2;
p_fqname alias for $3;
p_tab_idxname alias for $4;
p_tab_comment alias for $5;
v_set_origin int4;
begin
-- ----
-- Grab the central configuration lock
-- ----
lock table sl_config_lock;
-- ----
-- Check that we are the origin of the set
-- ----
select set_origin into v_set_origin
from sl_set
where set_id = p_set_id;
if not found then
raise exception 'Slony-I: setAddTable(): set % not found', p_set_id;
end if;
if v_set_origin != getLocalNodeId('_schemadoc') then
raise exception 'Slony-I: setAddTable(): set % has remote origin', p_set_id;
end if;
if exists (select true from sl_subscribe
where sub_set = p_set_id)
then
raise exception 'Slony-I: cannot add table to currently subscribed set % - must attach to an unsubscribed set',
p_set_id;
end if;
-- ----
-- Add the table to the set and generate the SET_ADD_TABLE event
-- ----
perform setAddTable_int(p_set_id, p_tab_id, p_fqname,
p_tab_idxname, p_tab_comment);
return createEvent('_schemadoc', 'SET_ADD_TABLE',
p_set_id::text, p_tab_id::text, p_fqname::text,
p_tab_idxname::text, p_tab_comment::text);
end; |