2 -- Test cases for COPY (INSERT/UPDATE/DELETE) TO
4 create table copydml_test (id serial, t text);
5 insert into copydml_test (t) values ('a');
6 insert into copydml_test (t) values ('b');
7 insert into copydml_test (t) values ('c');
8 insert into copydml_test (t) values ('d');
9 insert into copydml_test (t) values ('e');
11 -- Test COPY (insert/update/delete ...)
13 copy (insert into copydml_test (t) values ('f') returning id) to stdout;
15 copy (update copydml_test set t = 'g' where t = 'f' returning id) to stdout;
17 copy (delete from copydml_test where t = 'g' returning id) to stdout;
20 -- Test \copy (insert/update/delete ...)
22 \copy (insert into copydml_test (t) values ('f') returning id) to stdout;
24 \copy (update copydml_test set t = 'g' where t = 'f' returning id) to stdout;
26 \copy (delete from copydml_test where t = 'g' returning id) to stdout;
29 copy (insert into copydml_test default values) to stdout;
30 ERROR: COPY query must have a RETURNING clause
31 copy (update copydml_test set t = 'g') to stdout;
32 ERROR: COPY query must have a RETURNING clause
33 copy (delete from copydml_test) to stdout;
34 ERROR: COPY query must have a RETURNING clause
35 create rule qqq as on insert to copydml_test do instead nothing;
36 copy (insert into copydml_test default values) to stdout;
37 ERROR: DO INSTEAD NOTHING rules are not supported for COPY
38 drop rule qqq on copydml_test;
39 create rule qqq as on insert to copydml_test do also delete from copydml_test;
40 copy (insert into copydml_test default values) to stdout;
41 ERROR: DO ALSO rules are not supported for COPY
42 drop rule qqq on copydml_test;
43 create rule qqq as on insert to copydml_test do instead (delete from copydml_test; delete from copydml_test);
44 copy (insert into copydml_test default values) to stdout;
45 ERROR: multi-statement DO INSTEAD rules are not supported for COPY
46 drop rule qqq on copydml_test;
47 create rule qqq as on insert to copydml_test where new.t <> 'f' do instead delete from copydml_test;
48 copy (insert into copydml_test default values) to stdout;
49 ERROR: conditional DO INSTEAD rules are not supported for COPY
50 drop rule qqq on copydml_test;
51 create rule qqq as on update to copydml_test do instead nothing;
52 copy (update copydml_test set t = 'f') to stdout;
53 ERROR: DO INSTEAD NOTHING rules are not supported for COPY
54 drop rule qqq on copydml_test;
55 create rule qqq as on update to copydml_test do also delete from copydml_test;
56 copy (update copydml_test set t = 'f') to stdout;
57 ERROR: DO ALSO rules are not supported for COPY
58 drop rule qqq on copydml_test;
59 create rule qqq as on update to copydml_test do instead (delete from copydml_test; delete from copydml_test);
60 copy (update copydml_test set t = 'f') to stdout;
61 ERROR: multi-statement DO INSTEAD rules are not supported for COPY
62 drop rule qqq on copydml_test;
63 create rule qqq as on update to copydml_test where new.t <> 'f' do instead delete from copydml_test;
64 copy (update copydml_test set t = 'f') to stdout;
65 ERROR: conditional DO INSTEAD rules are not supported for COPY
66 drop rule qqq on copydml_test;
67 create rule qqq as on delete to copydml_test do instead nothing;
68 copy (delete from copydml_test) to stdout;
69 ERROR: DO INSTEAD NOTHING rules are not supported for COPY
70 drop rule qqq on copydml_test;
71 create rule qqq as on delete to copydml_test do also insert into copydml_test default values;
72 copy (delete from copydml_test) to stdout;
73 ERROR: DO ALSO rules are not supported for COPY
74 drop rule qqq on copydml_test;
75 create rule qqq as on delete to copydml_test do instead (insert into copydml_test default values; insert into copydml_test default values);
76 copy (delete from copydml_test) to stdout;
77 ERROR: multi-statement DO INSTEAD rules are not supported for COPY
78 drop rule qqq on copydml_test;
79 create rule qqq as on delete to copydml_test where old.t <> 'f' do instead insert into copydml_test default values;
80 copy (delete from copydml_test) to stdout;
81 ERROR: conditional DO INSTEAD rules are not supported for COPY
82 drop rule qqq on copydml_test;
83 create rule qqq as on insert to copydml_test do instead notify copydml_test;
84 copy (insert into copydml_test default values) to stdout;
85 ERROR: COPY query must not be a utility command
86 drop rule qqq on copydml_test;
88 create function qqq_trig() returns trigger as $$
90 if tg_op in ('INSERT', 'UPDATE') then
91 raise notice '% % %', tg_when, tg_op, new.id;
94 raise notice '% % %', tg_when, tg_op, old.id;
99 create trigger qqqbef before insert or update or delete on copydml_test
100 for each row execute procedure qqq_trig();
101 create trigger qqqaf after insert or update or delete on copydml_test
102 for each row execute procedure qqq_trig();
103 copy (insert into copydml_test (t) values ('f') returning id) to stdout;
104 NOTICE: BEFORE INSERT 8
106 NOTICE: AFTER INSERT 8
107 copy (update copydml_test set t = 'g' where t = 'f' returning id) to stdout;
108 NOTICE: BEFORE UPDATE 8
110 NOTICE: AFTER UPDATE 8
111 copy (delete from copydml_test where t = 'g' returning id) to stdout;
112 NOTICE: BEFORE DELETE 8
114 NOTICE: AFTER DELETE 8
115 drop table copydml_test;
116 drop function qqq_trig();