Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fiLdm-0007lN-Lg for pgsql-bugs@arkaria.postgresql.org; Wed, 25 Jul 2018 15:23:51 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fiLdk-0000Aw-Av for pgsql-bugs@arkaria.postgresql.org; Wed, 25 Jul 2018 15:23:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fiLdk-0000Ap-3D for pgsql-bugs@lists.postgresql.org; Wed, 25 Jul 2018 15:23:48 +0000 Received: from mx.zeyos.com ([88.99.153.70]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fiLdg-00066q-PB for pgsql-bugs@lists.postgresql.org; Wed, 25 Jul 2018 15:23:47 +0000 Received: from mx.zeyos.com (localhost [127.0.0.1]) by mx.zeyos.com (Postfix) with ESMTP id 5EF675FB09 for ; Wed, 25 Jul 2018 17:23:43 +0200 (CEST) Authentication-Results: mx.zeyos.com (amavisd-new); dkim=pass (1024-bit key) reason="pass (just generated, assumed good)" header.d=zeyos.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=zeyos.com; h= content-transfer-encoding:content-type:content-type:mime-version :to:from:from:subject:subject:date:date; s=dkim; t=1532532202; x=1533396203; bh=of+qll/jpWohPVUFFDipfWC19zIrpU/WhLQDoGLOqpY=; b= VuK7xrI5WXALXVrE03+8lSLZf2ZoOG6Vfn0mzZFqQRniyRWsQ1eVxljKa2M5P8/o zyaT3BAlDiDrMgXLkQRAC1/RzNNcyPVI1lz9wL9TIVZyXVUeTgpTxQdZUga+I4Uf 8xreEdIa7uJVHkU7IEnPDFpd79VvCK4ZdA8L5lQGZ9c= X-Virus-Scanned: Debian amavisd-new at mx.zeyos.com Received: from mx.zeyos.com ([127.0.0.1]) by mx.zeyos.com (mx.zeyos.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id aWDOr6dsdsX6 for ; Wed, 25 Jul 2018 17:23:22 +0200 (CEST) Received: from [81.171.8.203] (unknown [81.171.8.203]) by mx.zeyos.com (Postfix) with ESMTPSA id 4D1C15FB0A for ; Wed, 25 Jul 2018 17:23:22 +0200 (CEST) Date: Wed, 25 Jul 2018 17:23:21 +0200 Subject: Domain Constraint Violation Error Messages From: Benjamin Coutu To: pgsql-bugs@lists.postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20180725152343.5EF675FB09@mx.zeyos.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hello,=0A=0APlease consider domains with domain constraints such as the fol= lowing:=0A=0A=09CREATE DOMAIN "t_txt" text NOT NULL=0A=09=09CONSTRAINT "dc_= txt" CHECK (VALUE <> '');=0A=0A=09CREATE DOMAIN "t_sha1" varchar(40) COLLAT= E "C" NOT NULL DEFAULT ''=0A=09=09CONSTRAINT "dc_sha1" CHECK (VALUE ~ '^([a= -f0-9]{40})?$');=0A=09=09=0A... and some table such as this contrived examp= le:=0A=0A=09CREATE TABLE "myusers" (=0A=09=09"name" "t_txt",=0A=09=09"email= " "t_txt",=0A=09=09"token" "t_sha1"=0A=09);=0A=09=09=0ANow, on inserting or= updating the table with invalid data, appropriate domain constraint violat= ions occur. But unfortunatly the associated error messages only reference t= he domain and not the underlying column, e.g. "ERROR: domain public.t_txt d= oes not allow null values".=0A=0AThat is a huge problem. When domain types = are reused in a single table or across multiple tables/schemata it becomes = unclear and hard to debug because one doesn't know what specific data item = caused the violation as there is no reference to the originating column. In= the example above, even a single INSERT INTO "myusers" statement with a co= nstraint violation on the "t_txt" domain wouldn't be clear on whether it or= iginated because of a bad value in "name" or "email". The use of multi-stat= ement queries and writable CTEs make this problem even worse.=0A=0AOn stack= overflow there are some comments suggesting that one should simply stick to= single-use domains, but then what's the benefit of using custom domains in= the first place? IMHO the biggest value of domain types is the reusability= accross the entire database. In our case whe have one base/public schema w= ith a set of domain types and multiple uniform schemata (think multi-tenanc= y) with thousands of tables that reference those few same domains. This all= ows us to make universal schema changes easier and more efficient, and it a= lso saves a lot of redundant catalog data, such as repetitive column level = constraints and default expressions).=0A=0AIs there any way you could displ= ay the underlying column and schema-qualified table names at least as DETAI= L on cosntraint violation?=0AI'm aware that this is not per se a bug, but w= ithout the column info, domains are somewhat useless for all practical purp= oses. Wouldn't you agree?=0A=0AThanks in advance.=0A=0ABenjamin Coutu=0A=0A= ZeyOS, Inc.=0A=0Aben.coutu@zeyos.com=0Ahttp://www.zeyos.com