Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uP6WW-000Oa6-8T for pgsql-general@arkaria.postgresql.org; Tue, 10 Jun 2025 21:28:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1uP6WU-00A6J5-As for pgsql-general@arkaria.postgresql.org; Tue, 10 Jun 2025 21:28:46 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1uP6WU-00A6In-00 for pgsql-general@lists.postgresql.org; Tue, 10 Jun 2025 21:28:46 +0000 Received: from mail-oi1-x22b.google.com ([2607:f8b0:4864:20::22b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uP6WT-001Ixi-0E for pgsql-general@lists.postgresql.org; Tue, 10 Jun 2025 21:28:46 +0000 Received: by mail-oi1-x22b.google.com with SMTP id 5614622812f47-407a6c6a6d4so1803669b6e.1 for ; Tue, 10 Jun 2025 14:28:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1749590922; x=1750195722; darn=lists.postgresql.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=vdZXNJp+iDP5Apq4s3zABBNjuFC2Riy5Z1XDAr7iasE=; b=GjJZbnSV5OjJU2xthjdRw7AE2EgU5bWhpcuCYp/viJsOjMa6XMP3ymRTa3lFgDtQY5 z2MD9IgHZiSrAN5Re7ufJ47aQOeKYDuOdtUl3Nf7OJroKAr1kWi4PelGJr8dPVzXJi7S Baynp2lUM8RWFobQs3cibfmmADFRIjdYLpy07+ZmipiggkGKDF++bmizR8Lu9FHKr/hb rdL1Z9kGNqXOxGo7XTIjud0JL1/B/r0hjjLE4324gV0gVUho6dEmizqhYISf2w4AnWqd 2LCUkO+DrIrHO3cTOEjc4B5y1rZ4DLttxzXKM4az2uXoKxPvwbnzRpX0f8pKM8idmVhl hwxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1749590922; x=1750195722; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=vdZXNJp+iDP5Apq4s3zABBNjuFC2Riy5Z1XDAr7iasE=; b=IUngXGFdSBbr2wukDoWa/7wYXHb6ca7mjS3pwTPNxQ2YdDYYr9yl/z3tKQj7mBfBef h9GiQVL61KzocYo3p1rRRgXv5EO+7sXCf/GI4B2XU4NKYQPHqMvfvihqHJH0hU57cUen Ie491ttdldqlqQyt6A5RgpjWqOzq9M+H0Kb87kdBVc9mvR4pNWBl5EcvuR6u9gj8rJx4 5bUIfKwXGDz6guFOzZlyxKPkKRhcuGy75Y4cc2/QWycnXLrta/gExy8ZSjrHzOIxaXi2 O6lOjkaC9Ub1OnwurAxOHpYAinS8t5V5uRTqUvfSPi7hpoiZFJSpNXfFrJOQDHkdJv1a mzBQ== X-Gm-Message-State: AOJu0Yx5vssyRvq4nHxSIz1q9YqyRzHxzWUpU4kOY9TqgKfAtnRIfuGw DAUXDYrT6i+Xiou+7xse8/6fPWA4BWwamvm0Wbgr1gBr4Maeyi1HSxlSyCasHejzD4WWgzA4Txf ZS+oj6Wz9F+2v+mmp6sQvgafoDo6Vb5Jf3cGK X-Gm-Gg: ASbGncukATQ3MuW+3RgJMjquqwnKdiqGQ1zN+btDaLQMVB7Z9pyEHmqPUfDv4GjuIZ/ tAAm0sW0Czfr6WoImrSBqa3I/FfbH6gBMtbTWiq+sljhULMxeAe8ujiMn6kZPgopPBljDIhSjp8 9hNVZDsXRX4ixRLn5303/KMOxVlZ4ZevHdNwju1CUUlyhi X-Google-Smtp-Source: AGHT+IFqkML0hzXRuMLZwD3bam7aCf2L7ijs1JUZ0mqS9Ryqvblbtses6v+sEMHViR/zdhVzoZLYi/Xi7C50JvO7lwM= X-Received: by 2002:a05:6871:5285:b0:2ea:7963:534e with SMTP id 586e51a60fabf-2ea96c79893mr608524fac.14.1749590922437; Tue, 10 Jun 2025 14:28:42 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Ron Johnson Date: Tue, 10 Jun 2025 17:28:31 -0400 X-Gm-Features: AX0GCFvZymeY7qqgrLhurJmNAZmhbcboWLhLT5CrGs_NRs0tuZCFpqN9K5wVFow Message-ID: Subject: Re: Is it correct to raise an exception in a domain check To: "pgsql-generallists.postgresql.org" Content-Type: multipart/alternative; boundary="0000000000006f292f06373e61ec" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000006f292f06373e61ec Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Jun 10, 2025 at 4:53=E2=80=AFPM Logan Grosz = wrote: > 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 benef= it > from attaching a description to the client error. > Since PG will throw an error when any CHECK constraint fails, are you hoping to provide more details by throwing your own exception? --=20 Death to , and butter sauce. Don't boil me, I'm still alive. lobster! --0000000000006f292f06373e61ec Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Tue, Jun 10, 2025 at 4:53=E2=80=AFPM L= ogan Grosz <logan.grosz@gmail.c= om> wrote:
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
=

>=C2=A0Each constraint must be an expression produci= ng 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=C2=A0to the cl= ient error.

Since PG will throw= an error when any CHECK constraint fails, are you hoping to provide more d= etails by throwing your own exception?

--
Death to <Redacted>, and butter sauce.Don't boil me, I'm still alive.
<Redacted> lob= ster!
--0000000000006f292f06373e61ec--