
-- create table S (id integer, val text);
-- create table T (s integer, value text);

create or replace function
   check_T_insert_fk() returns trigger
as $$
begin
    perform * from S where id = new.s;
    if (not found) then
	raise NOTICE 'Invalid T.s value %',new.s;
        return null;
    else
        return new;
    end if;
end;
$$ language plpgsql;

create trigger T_fk_insert_check
before insert on T
for each row execute
procedure check_T_insert_fk();
