1.106. tabledropkey( integer )

関数特性

言語: PLPGSQL

戻り値: integer

tableDropKey (tab_id) もし特定されたテーブルに列 "_Slony-I_<clustername>_rowID" が存在すれば削除します。

declare
	p_tab_id		alias for $1;
	v_tab_fqname		text;
	v_tab_oid		oid;
begin
	-- ----
	-- 中枢構成のロックを取得
	-- ----
	lock table sl_config_lock;

	-- ----
	-- テーブルの完全修飾名(Fully Qualified Name)を構築し、そのオブジェクト識別子(oid)を受け取ります。
	-- ----
	select slon_quote_brute(PGN.nspname) || '.' ||
				slon_quote_brute(PGC.relname),
				PGC.oid into v_tab_fqname, v_tab_oid
			from sl_table T,
				"pg_catalog".pg_class PGC,
				"pg_catalog".pg_namespace PGN
			where T.tab_id = p_tab_id
				and T.tab_reloid = PGC.oid
				and PGC.relnamespace = PGN.oid;
	if not found then
		raise exception 'Slony-I: table with ID % not found', p_tab_id;
	end if;

	-- ----
	-- もしテーブルに特別なシリアル識別子列が存在すれば削除します。
	-- ----
	if exists (select true from "pg_catalog".pg_attribute
			where attrelid = v_tab_oid
				and attname = '_Slony-I_schemadoc_rowID')
	then
		execute 'lock table ' || v_tab_fqname ||
				' in access exclusive mode';
		execute 'alter table ' || v_tab_fqname ||
				' drop column "_Slony-I_schemadoc_rowID"';
	end if;

	return p_tab_id;
end;