Slony-I 2.1.1 Documentation
Prev | Fast Backward | Chapter 8. Schema schemadoc | Fast Forward | Next

# 8.83. log_truncate()

Function Properties

Language: PLPGSQL

Return Type: trigger

trigger function run when a replicated table receives a TRUNCATE request

    	declare
    		c_command text;
    		c_log integer;
    		c_node integer;
    		c_tabid integer;
    	begin
            c_tabid := tg_argv[0];
    	    c_node := getLocalNodeId('_schemadoc');
    		c_command := 'TRUNCATE TABLE ONLY "' || tab_nspname || '"."' ||
    				  tab_relname || '" CASCADE'
    				  from sl_table where tab_id = c_tabid;
    		select last_value into c_log from sl_log_status;
    		if c_log in (0, 2) then
    		   insert into sl_log_1 (log_origin, log_txid, log_tableid, log_actionseq, log_cmdtype, log_cmddata)
    		      values (c_node, pg_catalog.txid_current(), c_tabid, nextval('"_schemadoc".sl_action_seq'), 'T', c_command);
    		else   -- (1, 3)
    		   insert into sl_log_2 (log_origin, log_txid, log_tableid, log_actionseq, log_cmdtype, log_cmddata)
    		      values (c_node, pg_catalog.txid_current(), c_tabid, nextval('"_schemadoc".sl_action_seq'), 'T', c_command);
    		end if;
    		return NULL;
        end

Prev | Home | Next
lockset(p_set_id integer) | Up | logswitch_finish()