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 1tj4af-005gQ7-48 for pgsql-bugs@arkaria.postgresql.org; Fri, 14 Feb 2025 22:55:21 +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 1tj4ad-00EkJa-1h for pgsql-bugs@arkaria.postgresql.org; Fri, 14 Feb 2025 22:55:19 +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 1tj4ac-00EkJP-Q5 for pgsql-bugs@lists.postgresql.org; Fri, 14 Feb 2025 22:55:18 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1tj4aa-000t4X-1P for pgsql-bugs@lists.postgresql.org; Fri, 14 Feb 2025 22:55:18 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 51EMtEJE3914797; Fri, 14 Feb 2025 17:55:15 -0500 From: Tom Lane To: drtr0jan@yandex.ru cc: pgsql-bugs@lists.postgresql.org Subject: Re: BUG #18812: Conditional rule: inconsistent check for statement In-reply-to: <18812-565809b4823e2b68@postgresql.org> References: <18812-565809b4823e2b68@postgresql.org> Comments: In-reply-to PG Bug reporting form message dated "Fri, 14 Feb 2025 21:00:09 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3914795.1739573714.1@sss.pgh.pa.us> Date: Fri, 14 Feb 2025 17:55:14 -0500 Message-ID: <3914796.1739573714@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk PG Bug reporting form writes: > I've two rules for a view - unconditional INSTEAD (skip) and conditional > INSTEAD (always FALSE). But if I trying to insert a type mismatched data to > the view, I've got a type constraint error. [ shrug... ] The WHERE FALSE condition is evaluated later than it would need to be to prevent this error. If we use a value that doesn't trigger the error: =# explain verbose INSERT INTO v (c) VALUES ('testtest'); QUERY PLAN ------------------------------------------------------ Insert on public.t (cost=0.00..0.01 rows=0 width=0) -> Result (cost=0.00..0.01 rows=1 width=14) Output: 'testtest'::character varying(10) One-Time Filter: false (4 rows) we can see that the "false" is actually applied at runtime, but the value coercion happened during planner constant-folding. In general the order of application of WHERE clauses is not guaranteed, so there's not a good argument that this outcome is wrong. We get variants of this complaint from time to time, but few of them present use-cases that seem compelling enough to justify the performance costs of not doing constant-folding. regards, tom lane