Is it correct to raise an exception in a domain check

From: Logan Grosz <logan(dot)grosz(at)gmail(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Is it correct to raise an exception in a domain check
Date: 2025-06-09 04:01:47
Message-ID: CANn=KGi1fU3rkEbwnOZX3_WNQJXa39tbkmn7N4tAMSf75r7nNw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Greg Sabino Mullane 2025-06-09 13:38:37 Re: Feature request: Settings to disable comments and multiple statements in a connection
Previous Message Tom Lane 2025-06-07 23:08:10 Re: Feature request: Settings to disable comments and multiple statements in a connection