no-error-context-for-indexes1.sql

text/x-sql

Filename: no-error-context-for-indexes1.sql
Type: text/x-sql
Part: 0
Message: no error context for index updates?
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
$$;

DROP TABLE IF EXISTS test;
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;