log_truncate()

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