altertabledroptriggers(p_tab_id integer)

8.26. altertabledroptriggers(p_tab_id integer)

Function Properties

Language: PLPGSQL

Return Type: integer

alterTableDropTriggers (tab_id) Remove the log and deny access triggers from a table.

declare
	v_no_id				int4;
	v_tab_row			record;
	v_tab_fqname		text;
	v_n					int4;
begin
	-- ----
	-- Grab the central configuration lock
	-- ----
	lock table sl_config_lock;

	-- ----
	-- Get our local node ID
	-- ----
	v_no_id := getLocalNodeId('_schemadoc');

	-- ----
	-- Get the sl_table row and the current tables origin.
	-- ----
	select T.tab_reloid, T.tab_set,
			S.set_origin, PGX.indexrelid,
			slon_quote_brute(PGN.nspname) || '.' ||
			slon_quote_brute(PGC.relname) as tab_fqname
			into v_tab_row
			from sl_table T, sl_set S,
				"pg_catalog".pg_class PGC, "pg_catalog".pg_namespace PGN,
				"pg_catalog".pg_index PGX, "pg_catalog".pg_class PGXC
			where T.tab_id = p_tab_id
				and T.tab_set = S.set_id
				and T.tab_reloid = PGC.oid
				and PGC.relnamespace = PGN.oid
				and PGX.indrelid = T.tab_reloid
				and PGX.indexrelid = PGXC.oid
				and PGXC.relname = T.tab_idxname
				for update;
	if not found then
		raise exception 'Slony-I: alterTableDropTriggers(): Table with id % not found', p_tab_id;
	end if;
	v_tab_fqname = v_tab_row.tab_fqname;

	execute 'lock table ' || v_tab_fqname || ' in access exclusive mode';

	-- ----
	-- Drop both triggers
	-- ----
	execute 'drop trigger "_schemadoc_logtrigger" on ' || 
			v_tab_fqname;

	execute 'drop trigger "_schemadoc_denyaccess" on ' || 
			v_tab_fqname;
				
	perform alterTableDropTruncateTrigger(v_tab_fqname, p_tab_id);

	return p_tab_id;
end;