How to check for custom exceptions raised via RAISE
?
#1339
Answered
by
abhijit-hota
abhijit-hota
asked this question in
Q&A
-
I've a trigger function something like the following: CREATE OR REPLACE FUNCTION foo()
RETURNS TRIGGER AS
$$
BEGIN
IF (bar = 'baz') THEN
-- something
ELSE
RAISE EXCEPTION 'oops error';
END IF;
RETURN NEW;
END;
$$
LANGUAGE plpgsql; How do I check for that error in Golang code? |
Beta Was this translation helpful? Give feedback.
Answered by
abhijit-hota
Oct 18, 2022
Replies: 1 comment
-
Use var pgErr *pgconn.PgError
if errors.As(err, &pgErr) {
//pgErr has all the fluff
} |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
abhijit-hota
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use
*pgconn.PgError
: