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 1fnEbn-0005d0-Uw for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Aug 2018 02:54:00 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fnEbj-0006fh-NI for pgsql-bugs@arkaria.postgresql.org; Wed, 08 Aug 2018 02:53:55 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fnEbj-0006fa-Ag for pgsql-bugs@lists.postgresql.org; Wed, 08 Aug 2018 02:53:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fnEbg-0006Sy-1L for pgsql-bugs@lists.postgresql.org; Wed, 08 Aug 2018 02:53:53 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w782rnAn013062; Tue, 7 Aug 2018 22:53:49 -0400 From: Tom Lane To: lalbin@scharp.org cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15316: pg_restore failes to load data that is constrainted by a functional check constraints In-reply-to: <153368669319.1297.12136690880705121335@wrigleys.postgresql.org> References: <153368669319.1297.12136690880705121335@wrigleys.postgresql.org> Comments: In-reply-to =?utf-8?q?PG_Bug_reporting_form?= message dated "Wed, 08 Aug 2018 00:04:53 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <13060.1533696829.1@sss.pgh.pa.us> Date: Tue, 07 Aug 2018 22:53:49 -0400 Message-ID: <13061.1533696829@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk =?utf-8?q?PG_Bug_reporting_form?= writes: > I have found an edge case where pg_dump and pg_restore fails to restore > databases with check constraints that points to data in another table that > is restored after the table containing the check constraint. This is an unsupported case.[1] In general, table CHECK constraints are only allowed to concern themselves with the data in the particular row that they're checking. While we can't actually stop you from cheating by hiding the subquery in a function, we're not going to consider it a bug that such a setup doesn't work reliably. I'd suggest rethinking your data representation so that you can make the tables' relationship into a regular foreign key constraint. Those, the system understands well enough to maintain in a dump/reload context. regards, tom lane [1] Specifically, we disclaim support for SQL feature F671, "Subqueries in CHECK constraints".