CREATE EXTENSION IF NOT EXISTS plpythonu;

--CREATE DOMAIN pos_int AS int; --This version's leak is less severe.
CREATE DOMAIN pos_int AS int CHECK (VALUE >= 0); --This version's leak is more severe.

CREATE TYPE comp_type AS (var_a pos_int);
CREATE TABLE t (
	foo int,
	bar comp_type
);


--This trigger doesn't cause a leak.
CREATE FUNCTION trig_sql() RETURNS trigger
LANGUAGE plpgsql AS
$$
BEGIN
	NEW.bar = '(0)';
	
	RETURN NEW;
END;
$$;
--CREATE TRIGGER trig_name BEFORE INSERT ON t FOR EACH ROW EXECUTE PROCEDURE trig_sql();


--This trigger does cause a leak.
CREATE FUNCTION trig_python() RETURNS trigger
LANGUAGE plpythonu AS
$$
	TD['new']['bar'] = (0,)
	
	return 'MODIFY'
$$;
CREATE TRIGGER trig_name BEFORE INSERT ON t FOR EACH ROW EXECUTE PROCEDURE trig_python();
