no-error-context-for-indexes2.sql
text/x-sql
Filename: no-error-context-for-indexes2.sql
Type: text/x-sql
Part: 1
Message:
no error context for index updates?
CREATE OR REPLACE LANGUAGE plperl;
CREATE OR REPLACE FUNCTION test1(x int) RETURNS int
IMMUTABLE STRICT
LANGUAGE plperl
AS $$
elog(ERROR, "boom") if $_[0] < 0;
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 plperl
AS $$
$plan = spi_prepare('INSERT INTO test (a, b) VALUES ($1, $2)', 'int', 'text');
$rv = spi_exec_prepared($plan, $_[0], $_[1]);
return $rv->{processed};
$$;
SELECT test2(1, 'one');
SELECT test2(-1, 'neg one');
SELECT * FROM test;