CREATE OR REPLACE LANGUAGE plpythonu;

CREATE OR REPLACE FUNCTION test1(x int) RETURNS int
IMMUTABLE STRICT
LANGUAGE plpythonu
AS $$
if x < 0:
    plpy.error("boom")
return x
$$;

CREATE TABLE test (a int, b text);

CREATE INDEX ON test ((test1(a)));

CREATE OR REPLACE FUNCTION test2(a int, b text) RETURNS int
LANGUAGE plpythonu
AS $$
plan = plpy.prepare('INSERT INTO test (a, b) VALUES ($1, $2)', ['int', 'text'])
rv = plpy.execute(plan, [a, b])
return rv.nrows()
$$;

SELECT test2(1, 'one');
SELECT test2(-1, 'neg one');

SELECT * FROM test;
