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.96) (envelope-from ) id 1wux9o-0010NI-2e for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Aug 2026 19:01:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wux9m-002DGJ-2E for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Aug 2026 19:01:31 +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.96) (envelope-from ) id 1wux9m-002DG5-1I for pgsql-hackers@lists.postgresql.org; Fri, 14 Aug 2026 19:01:31 +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.98.2) (envelope-from ) id 1wux9k-00000000ks4-3hT5 for pgsql-hackers@postgresql.org; Fri, 14 Aug 2026 19:01:31 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.18.1/8.18.1) with ESMTP id 67EJ1JlL3778323; Fri, 14 Aug 2026 15:01:19 -0400 From: Tom Lane To: Isaac Morland cc: Robert Haas , Paul A Jungwirth , Erik Wienhold , Said Assemlal , pgsql-hackers@postgresql.org, Haibo Yan Subject: Re: CREATE OR REPLACE MATERIALIZED VIEW In-reply-to: References: <7afe68b0-f983-4a9f-a1b4-32188cebbf38@ewie.name> <64495e31-0a91-4894-87f8-31451ee69f44@ewie.name> <2724629.1743885428@sss.pgh.pa.us> <5cd7ec92-ee61-4080-8fb6-0aed6a51eeaf@ewie.name> <6d710ac3-3a66-4b31-b35a-0b4d9afdda42@ewie.name> <3774197.1786730718@sss.pgh.pa.us> Comments: In-reply-to Isaac Morland message dated "Fri, 14 Aug 2026 14:27:26 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3778321.1786734079.1@sss.pgh.pa.us> Date: Fri, 14 Aug 2026 15:01:19 -0400 Message-ID: <3778322.1786734079@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Isaac Morland writes: > This sounds like CREATE OR REPLACE to me, even if there is something to > explain in the documentation about what happens to the existing data > (assuming it is currently populated). I don't think of CREATE OR REPLACE as > completely re-creating an object anyhow. Certainly it can't arbitrarily > replace a function (can't change return type) nor a view (can't remove or > change type of a column). It's OK if not all possible changes are supported > by the "OR REPLACE" part of the command. To my mind, the formal requirement for CREATE OR REPLACE should be "if the command succeeds, the resulting object properties are identical to what they'd be if we were creating it fresh" -- basically a form of idempotency. It's okay to fail when there are reasons why we can't or shouldn't make that so. In particular, ISTM that if we invent CREATE OR REPLACE MATERIALIZED VIEW, then the view content should be either computed afresh or left empty (depending on WITH NO DATA); it should never leave stale data. But I think Robert is correct that an ALTER command that does keep the old data is often going to be what's wanted. regards, tom lane