create table buggy_uq (
	i integer unique not null
);

create table buggy_uq_parent (
	i integer primary key
);

create table buggy_uq_child (
	i integer unique references buggy_uq_parent on delete cascade
);

create or replace function bug_case1()
returns void as '
--case 1 prepare
delete from buggy_uq;
insert into buggy_uq values (1);
insert into buggy_uq values (2);
--case 1 test
update buggy_uq set i = i + 1;
' language sql;

create or replace function bug_case2()
returns void as '
--case 2 prepare
delete from buggy_uq_child;
delete from buggy_uq_parent;
insert into buggy_uq_parent values (1);
insert into buggy_uq_child values (1);
--case 2 test
delete from buggy_uq_parent;
insert into buggy_uq_child values (1);
' language sql;

create or replace function bug_case3()
returns void as '
--case 3 prepare
delete from buggy_uq_child;
delete from buggy_uq_parent;
insert into buggy_uq_parent values (1);
insert into buggy_uq_child values (1);
delete from buggy_uq_child;
delete from buggy_uq_parent;
--case 3 test
insert into buggy_uq_child values (1);
' language sql;