public inbox for [email protected]
help / color / mirror / Atom feedFrom: Tom Lane <[email protected]>
To: Logan Grosz <[email protected]>
Cc: [email protected]
Subject: Re: Is it correct to raise an exception in a domain check
Date: Tue, 10 Jun 2025 17:31:04 -0400
Message-ID: <[email protected]> (raw)
In-Reply-To: <CANn=KGi1fU3rkEbwnOZX3_WNQJXa39tbkmn7N4tAMSf75r7nNw@mail.gmail.com>
References: <CANn=KGi1fU3rkEbwnOZX3_WNQJXa39tbkmn7N4tAMSf75r7nNw@mail.gmail.com>
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
view thread (2+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected]
Subject: Re: Is it correct to raise an exception in a domain check
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox