I want to perform some business validation of the data being inserted in a table and I need to check data in another table when doing so. The way to this seems to be using a BEFORE INSERT FOR EACH ROW TRIGGER in PostgreSQL and from the function it calls I can return NULL if the new data fails validation to prevent it being inserted.
Is there any way I can return an error message describing the validation error as well?