CREATE OR REPLACE FUNCTION allow_on_condition() RETURNS trigger AS $$ BEGIN { strict->import(); } use lib '/contrib'; use lib '/extensions'; use CheckTrigger; my $minargc = 1; my $return_condition = 0; # $minargc += 2; # $return_condition = 1; # should be called as a row-level trigger die "should be called as a row-level trigger" unless ($_TD->{level} eq 'ROW'); # check for the correct number of arguments die "$_TD->{name}, wrong number of arguments" unless ($_TD->{argc} >= $minargc); # my $assert = shift @{$_TD->{args}}; # my $error_text = shift @{$_TD->{args}}; # do a poor-man's quote_nullable for 8.3 and below # $assert = PLPerl::CheckTrigger::pg_quote_nullable($assert); # $error_text = PLPerl::CheckTrigger::pg_quote_nullable($error_text); my $condition = shift @{$_TD->{args}}; my @args = @{$_TD->{args}}; my $ch = new PLPerl::CheckTrigger($_TD); my $result; eval { $result = $ch->check_condition($condition, $return_condition, @args); }; die $@ if ($@); # my $returned_condition = $result; # my $query = "SELECT tools.assert($assert, ($returned_condition), $error_text)"; # my $rv = spi_exec_query($query); # return; if (!$result) { die $ch->{errmsg}; } return; $$ LANGUAGE plperlu;