The qustion's in the (albeit long) title. I have code in this fashion:
-- create the tables for models
CREATE TABLE invoice(
id SERIAL PRIMARY KEY,
value VARCHAR(8)
CONSTRAINT valid_money CHECK(validate_invoice_money(value))
);
with this procedure:
CREATE OR REPLACE FUNCTION validate_invoice_money(test VARCHAR) RETURNS BOOLEAN AS $$
import plpy
import re
if (re.match("^[0-9]+\\.[0-9]{2}$", test) == None):
return False
return True
$$ LANGUAGE plpython3u IMMUTABLE;
(the specifics of this example are not important, I know there's better ways to validate a value than this, such as using the MONEY
type.)
When an insert is attempted that fails this check, I get the following error:
ERROR : new row for relation "invoice" violates check constraint "valid_model"
DETAIL : Failing row contains (1, "notvalid").
(the error/detail descriptors are my own code, but a PostgreSQL error has an error and a detail field provided.)
Is there any way for me to change the "detail" portion of this error from my Python procedure?