関数特性
言語: PLPGSQL
戻り値: integer
setAddTable_int (set_id, tab_id, tab_fqname, tab_idxname, tab_comment) この関数は遠隔ノードの SET_ADD_TABLE 事象を、その複製セットを遠隔ノードが購読していれば、複製をテーブルに追加する処理をします。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_tab_relname name; v_tab_nspname name; v_local_node_id int4; v_set_origin int4; v_sub_provider int4; v_relkind char; v_tab_reloid oid; begin -- ---- -- 中枢構成にロックを取得 -- ---- lock table sl_config_lock; -- ---- -- 遠隔オリジンのセットに対して、そのセットに私たちが購読されて -- いるかの検査。さもなければ、私たちのデータベースには全く -- 存在しないであろうからそのテーブルを無視します。 -- ---- v_local_node_id := getLocalNodeId('_schemadoc'); 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_int(): set % not found', p_set_id; end if; if v_set_origin != v_local_node_id then select sub_provider into v_sub_provider from sl_subscribe where sub_set = p_set_id and sub_receiver = getLocalNodeId('_schemadoc'); if not found then return 0; end if; end if; -- ---- -- テーブルオブジェクト識別子(OID)を獲得し、それがテーブルか否かを検査します。 -- ---- select PGC.oid, PGC.relkind, PGC.relname, PGN.nspname into v_tab_reloid, v_relkind, v_tab_relname, v_tab_nspname from "pg_catalog".pg_class PGC, "pg_catalog".pg_namespace PGN where PGC.relnamespace = PGN.oid and slon_quote_input(p_fqname) = slon_quote_brute(PGN.nspname) || '.' || slon_quote_brute(PGC.relname); if not found then raise exception 'Slony-I: setAddTable(): table % not found', p_fqname; end if; if v_relkind != 'r' then raise exception 'Slony-I: setAddTable(): % is not a regular table', p_fqname; end if; if not exists (select indexrelid from "pg_catalog".pg_index PGX, "pg_catalog".pg_class PGC where PGX.indrelid = v_tab_reloid and PGX.indexrelid = PGC.oid and PGC.relname = p_tab_idxname) then raise exception 'Slony-I: setAddTable(): table % has no index %', p_fqname, p_tab_idxname; end if; -- ---- -- テーブルを sl_table に追加し、その上にトリガーを作成します。 -- ---- insert into sl_table (tab_id, tab_reloid, tab_relname, tab_nspname, tab_set, tab_idxname, tab_altered, tab_comment) values (p_tab_id, v_tab_reloid, v_tab_relname, v_tab_nspname, p_set_id, p_tab_idxname, false, p_tab_comment); perform alterTableForReplication(p_tab_id); return p_tab_id; end;