_ | 覦覈襦 | 豕蠏手 | 殊螳 | 譯殊碁
FrontPage › PostgreSQLPartitioning

data type 襷讌 朱, trigger 蠍磯 觧.

drop table test_child1;
drop table test_child2;
drop table test_parent;

--覿覈 企
create table test_parent(
	id int
,	logs json
,	src text
);

--企: 一 豢螳
create table test_child1(check(id = 1)) inherits (test_parent);
create table test_child2(check(id = 2)) inherits (test_parent);

--碁Μ蟇 
create or replace function test_insert_trigger()
returns trigger as
$$
declare logs json;
declare	ins_sql text;
begin
	logs := new.src;
	ins_sql='insert into test_child' ||new.id||'(id, logs) values('||new.id||', '''||new.src||''')';
	execute ins_sql;
	return null;
exception
	when others then
		ins_sql='insert into test_child' ||new.id||'(id, src) values('||new.id||', '''||new.src||''')';
		execute ins_sql;
		return null;
end;
$$ language plpgsql;

--碁Μ蟇
create trigger insert_test_trigger
    before insert on test_parent
    for each row execute procedure test_insert_trigger();

--ろ
insert into test_parent(id, src) values(1, '{"kr":"覩手記", "en":"KOREA"}');
insert into test_parent(id, src) values(1, '{"kr":"覩手記", "en":"KOREA"');

select * from test_parent;


--一  ?
select * from test_parent
where id = 1;

/*
"Append  (cost=0.00..20.38 rows=5 width=68)"
"  ->  Seq Scan on test_parent  (cost=0.00..0.00 rows=1 width=68)"
"        Filter: (id = 1)"
"  ->  Seq Scan on test_child1  (cost=0.00..20.38 rows=4 width=68)"
"        Filter: (id = 1)"
*/

--一 
alter table test_child1 no inherit test_parent;

select * from test_parent
where id = 1;
--0 rows

--drop table test_child1
蠍 蠍郁鍵..
企: : るジ讓曙 襦螻豺 企Ν 譯殊語. 襦螻豺
EditText : Print : Mobile : FindPage : DeletePage : LikePages : Powered by MoniWiki : Last modified 2018-04-13 23:12:53

覓企 覓殊企 讌碁ゼ 磯 襯企 豺讌 螻 讌襯 螳豢 螳螻 讌企伎 襦 螳 襯 螳豢 螳朱 企 蟾 螻葛 襾碁蟇磯Μ讌 螻 れ願 蠍磯ゼ 螳讌 螳螻 レ覓殊 襷 螳覃 螻 襷讌 豌覈 螳朱 螻褐 蟇一 覃襴 襯伎襷 覓殊企襴 覯 朱 螳讌 螳. 豌讌 願朱 企伎螻 襷覓殊 願朱 伎螳覃 朱 願朱 至 襷 願朱 伎覃 襷覓殊 願朱 覦襯願 蟆企. 願 讌襦 螳 覓殊 譬 伎企. ( <<語>>)