创建do instead nothing规则, 例如
digoal=> create rule r_insert as on insert to test do instead nothing;
CREATE RULE
digoal=> insert into test values (1);
INSERT 0 0
digoal=> select * from test ;
id
----
(0 rows)
以上方法对COPY无法生效,因为COPY不走重写规则。
要让所有数据都无法进入,可以用行触发器。
pipeline=# create or replace function tg() returns trigger as
$$
pipeline$# declare
pipeline$# begin
pipeline$# return null;
pipeline$# end;
pipeline$#
$$
language plpgsql;
pipeline=# create trigger tg1 before insert on tbl for each row execute procedure tg();
CREATE TRIGGER
pipeline=# \d tbl
Table "public.tbl"
Column | Type | Modifiers
--------+---------+-----------
v_d | date |
data | numeric |
month | numeric |
year | numeric |
Triggers:
tg1 BEFORE INSERT ON tbl FOR EACH ROW EXECUTE PROCEDURE tg()
pipeline=# insert into tbl values ('2015-01-01');
INSERT 0 0
pipeline=# copy tbl from stdin;
Enter data to be copied followed by a newline.
End with a backslash and a period on a line by itself.
>> '2015-01-01' \N \N \N
>> \.
COPY 0
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。