Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lTsmk-0008Q3-6Q for pgsql-general@arkaria.postgresql.org; Tue, 06 Apr 2021 20:58:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lTsmj-0003XB-35 for pgsql-general@arkaria.postgresql.org; Tue, 06 Apr 2021 20:58:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lTsmi-0003X4-NC for pgsql-general@lists.postgresql.org; Tue, 06 Apr 2021 20:58:52 +0000 Received: from mail-oi1-x229.google.com ([2607:f8b0:4864:20::229]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lTsmf-0001nr-FD for pgsql-general@lists.postgresql.org; Tue, 06 Apr 2021 20:58:52 +0000 Received: by mail-oi1-x229.google.com with SMTP id k25so16554233oic.4 for ; Tue, 06 Apr 2021 13:58:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language; bh=hqZBhL1uFJ5S8zVAAMw4Lv+xgjzxZ3urD4aZRVaAtVQ=; b=bzpaqoj1vwxUUFd6pgqHZiV1Ly5U9OriGyA1/RPs7hqI6QIqLFVtOzgHOIepLaOvWK 90RqL98JkoNFQaBNjF8ByRvCwJgxihuxJ8JCyFzl89ZA1RzpIetQKVHG6GdZAFtyFgwA Cuv3DtFoifEn/tfFcTFNWxanfYKHV4KtD7a9XuaN1Sxh0g7WqJ3X5thwMOVRTwwgAEzx xrVHbSYfboEsZKnXLlCYI8zdW7trm8/tPZOCul4zwQU+hsBGO2eH/VUGXxc5Spt6uOLw 01XAHflYAL4Dg1O0xGFYWeA2UBGcbyl+B6AOuwj0RJp/Jw5CzUiAzNyQWErB7h5ENJy8 cawQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language; bh=hqZBhL1uFJ5S8zVAAMw4Lv+xgjzxZ3urD4aZRVaAtVQ=; b=lkzcK4sUGjiDMAROqV0Ayp0HdIiZkFdo5esnf4c5KkNMDCkxSop0s2Q9JYOJCGulC+ X9JVKL+/IIHrpstaK4tc9HRSCsltB+8grgHB0+0M8eSn9kvKs35U00CeOzYE4vRkjqVt C0Cpl+J0pqjOLJkA0C9g15L145PCsDx0n/zh+FZARWRgNf9aekg1D8qSi1AFaAZYfHze 6MaoFbAy0stkPuKV/jameja/uuADumIOwL2ZWWOPMkTNBPcA2Bx+oXTkUbNMl6mPz4kn w3yTDS4/2Vc1od18NPKLGO3hp++UwOVy1b26/2+YlaEBAFAKdh9OS6IP1NYTkjHgu5e3 kSdg== X-Gm-Message-State: AOAM532hbn77RvwHXwzzD8NYe/XVVYdf9+i0nTMFMFTGkF2UboslIGHu wvYCv1eJXN8rqQXyHPazMZ4owh+IoR0= X-Google-Smtp-Source: ABdhPJwuRB9d+s+wJoENuggAH+9lzgzZrbtC5DACitlpBVDDFUgHVVfHlsk3kdQFjJ+6n+lbEaxdOQ== X-Received: by 2002:aca:3f87:: with SMTP id m129mr4736315oia.82.1617742727076; Tue, 06 Apr 2021 13:58:47 -0700 (PDT) Received: from [192.168.88.10] (ip174-67-141-204.no.no.cox.net. [174.67.141.204]) by smtp.googlemail.com with ESMTPSA id i17sm4826249ota.53.2021.04.06.13.58.46 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 06 Apr 2021 13:58:46 -0700 (PDT) Subject: Re: Check constraint failure messages To: pgsql-general References: From: Ron Message-ID: Date: Tue, 6 Apr 2021 15:58:45 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: multipart/alternative; boundary="------------A47BBAD3310A358F695A4AF8" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is a multi-part message in MIME format. --------------A47BBAD3310A358F695A4AF8 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit On 4/6/21 3:50 PM, Miles Elam wrote: > On Tue, Apr 6, 2021 at 1:03 PM Ron > wrote: > > On 4/6/21 2:40 PM, Miles Elam wrote: >> I've got a domain that validates email addresses. When inserting a >> bunch of entries I simply get the error message >> >> ERROR: value for domain po.email violates check constraint >> "email_check" SQL state: 23514 >> >> >> When inserting 1000+ entries in a batch, finding the exact entry with >> the problem is noticeably harder than with other error types. For >> example when a column should be a uuid but you pass in 'Mary had a >> little lamb', the error message tells you what the invalid value is >> as well as the column name you're trying to put it into. >> >> Are there any quick hacks floating around out there to solve or at >> least mitigate this? > > Is it a deferred constraint? > > Plain ole domain CHECK constraint. > > CREATE DOMAIN po.email AS varchar >   CHECK (VALUE IS NULL OR (po.length_in(VALUE, 1, 254) AND NOT > po.email_expanded(VALUE) IS NULL)); > > > where "po" is another schema, po.length_in(...) is an IMMUTABLE range > check, and po.email_expanded(...) is a function returning a record. Same > behavior happens if I remove the functions and define the check constraint > in place. The only info returned in a bulk insert is the name of the > violated check constraint, aka email_check. The blunt force answer is to not use bulk inserts.  Try COPY; it's good at saying which record throws an error. -- Angular momentum makes the world go 'round. --------------A47BBAD3310A358F695A4AF8 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit On 4/6/21 3:50 PM, Miles Elam wrote:
On Tue, Apr 6, 2021 at 1:03 PM Ron <ronljohnsonjr@gmail.com> wrote:
On 4/6/21 2:40 PM, Miles Elam wrote:
I've got a domain that validates email addresses. When inserting a bunch of entries I simply get the error message

ERROR: value for domain po.email violates check constraint "email_check" SQL state: 23514

When inserting 1000+ entries in a batch, finding the exact entry with the problem is noticeably harder than with other error types. For example when a column should be a uuid but you pass in 'Mary had a little lamb', the error message tells you what the invalid value is as well as the column name you're trying to put it into.

Are there any quick hacks floating around out there to solve or at least mitigate this?

Is it a deferred constraint?
 
Plain ole domain CHECK constraint.

CREATE DOMAIN po.email AS varchar
  CHECK (VALUE IS NULL OR (po.length_in(VALUE, 1, 254) AND NOT po.email_expanded(VALUE) IS NULL));

where "po" is another schema, po.length_in(...) is an IMMUTABLE range check, and po.email_expanded(...) is a function returning a record. Same behavior happens if I remove the functions and define the check constraint in place. The only info returned in a bulk insert is the name of the violated check constraint, aka email_check.

The blunt force answer is to not use bulk inserts.  Try COPY; it's good at saying which record throws an error.

--
Angular momentum makes the world go 'round.
--------------A47BBAD3310A358F695A4AF8--