public inbox for [email protected]
help / color / mirror / Atom feedIs it correct to raise an exception in a domain check
2+ messages / 2 participants
[nested] [flat]
* Is it correct to raise an exception in a domain check
@ 2025-06-09 04:01 Logan Grosz <[email protected]>
2025-06-10 21:31 ` Re: Is it correct to raise an exception in a domain check Tom Lane <[email protected]>
0 siblings, 1 reply; 2+ messages in thread
From: Logan Grosz @ 2025-06-09 04:01 UTC (permalink / raw)
To: [email protected]
Hi,
I have a `DOMAIN` on `JSONB`. I need to verify the shape of the JSON, so I
have a check expression written in PL/pgSQL. The docs say
> Each constraint must be an expression producing a Boolean result
Would it be correct to raise an exception to indicate a failed check? I
perform type-casts (that throw already) and other checks that would benefit
from attaching a description to the client error.
Thank you,
Logan
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Is it correct to raise an exception in a domain check
2025-06-09 04:01 Is it correct to raise an exception in a domain check Logan Grosz <[email protected]>
@ 2025-06-10 21:31 ` Tom Lane <[email protected]>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2025-06-10 21:31 UTC (permalink / raw)
To: Logan Grosz <[email protected]>; +Cc: [email protected]
Logan Grosz <[email protected]> writes:
> I have a `DOMAIN` on `JSONB`. I need to verify the shape of the JSON, so I
> have a check expression written in PL/pgSQL. The docs say
>> Each constraint must be an expression producing a Boolean result
> Would it be correct to raise an exception to indicate a failed
> check?
It'd be better just to have the CHECK expression return false.
Admittedly, that's usually just going to end in an exception,
but pre-judging that inside the expression doesn't seem ideal.
An example of why not is that you'd break "soft" input error
handling in COPY.
As you say, there are some cases where it's hard to avoid
an exception, but I'm not sure that "better error message"
is a good justification for throwing one. Still, in the
end it's your own judgment to make.
regards, tom lane
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2025-06-10 21:31 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-06-09 04:01 Is it correct to raise an exception in a domain check Logan Grosz <[email protected]>
2025-06-10 21:31 ` Tom Lane <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox