Show failing row in check constraint error

This commit is contained in:
Phil Freeman 2020-01-07 13:54:51 -08:00
parent acf0ce5c9a
commit dd2cac29d0
3 changed files with 13 additions and 5 deletions

View File

@ -315,7 +315,15 @@ insertPermsCheck tn insertResult cond sw =
(S.SEFunction
(S.FunctionExp
(QualifiedObject (SchemaName "hdb_catalog") (FunctionName "check_violation"))
(S.FunctionArgs [] mempty)
(S.FunctionArgs
[ S.SEOpApp (S.SQLOp " || ")
[ S.SELit "The record "
, S.SETyAnn (S.SERowIden insertResult) (S.TypeAnn "text")
, S.SELit " does not satisfy the check constraint."
]
]
mempty
)
Nothing)
)
] Nothing)

View File

@ -663,9 +663,9 @@ CREATE VIEW hdb_catalog.hdb_computed_field_function AS
FROM hdb_catalog.hdb_computed_field
);
CREATE OR REPLACE FUNCTION hdb_catalog.check_violation() RETURNS bool AS
CREATE OR REPLACE FUNCTION hdb_catalog.check_violation(msg text) RETURNS bool AS
$$
BEGIN
RAISE check_violation USING message='insert check constraint failed';
RAISE check_violation USING message=msg;
END;
$$ LANGUAGE plpgsql;

View File

@ -1,6 +1,6 @@
CREATE OR REPLACE FUNCTION hdb_catalog.check_violation() RETURNS bool AS
CREATE OR REPLACE FUNCTION hdb_catalog.check_violation(msg text) RETURNS bool AS
$$
BEGIN
RAISE check_violation USING message='insert check constraint failed';
RAISE check_violation USING message=msg;
END;
$$ LANGUAGE plpgsql;