Christopher B. Browne's Home Page
cbbrowne@acm.org

8.98. setaddtable(integer, integer, text, name, text)

Function Properties

PLPGSQLbigint
setAddTable (set_id, tab_id, tab_fqname, tab_idxname, tab_comment) Add table tab_fqname to replication set on origin node, and generate SET_ADD_TABLE event to allow this to propagate to other nodes. Note that the table id, tab_id, must be unique ACROSS ALL SETS.
    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;

Google

If this was useful, let others know by an Affero rating

Contact me at cbbrowne@acm.org