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 1wuwHl-000zwt-1E for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Aug 2026 18:05:41 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wuwHj-001vyI-0t for pgsql-hackers@arkaria.postgresql.org; Fri, 14 Aug 2026 18:05:40 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wuwHi-001vyA-2n for pgsql-hackers@lists.postgresql.org; Fri, 14 Aug 2026 18:05:39 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wuwHh-00000000dgm-1z76 for pgsql-hackers@postgresql.org; Fri, 14 Aug 2026 18:05:39 +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 67EI5I5K3774198; Fri, 14 Aug 2026 14:05:18 -0400 From: Tom Lane To: Robert Haas cc: 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> Comments: In-reply-to Robert Haas message dated "Fri, 14 Aug 2026 13:34:45 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3774196.1786730718.1@sss.pgh.pa.us> Date: Fri, 14 Aug 2026 14:05:18 -0400 Message-ID: <3774197.1786730718@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Robert Haas writes: > I think CREATE OR REPLACE is the wrong syntax here. I think what > people would most often want to do is edit the query used to refresh > the query without disturbing the existing data, indexes, or other > ancillary properties of the view in any way, but just changing what > happens on next refresh. We have CREATE OR REPLACE FUNCTION because > replacing a function in its entirety is a sensible thing to do, but we > don't have CREATE OR REPLACE TABLE because tables contain data that > you're unlikely to want to throw out. Materialized views are more like > tables in this respect: they have data. Granted, it can be > regenerated, but that's probably expensive. > So I'd propose that this should be a form of ALTER MATERIALIZED VIEW, > and that it be defined as suggested above, just replacing the refresh > query. This approach makes sense to me. Note that this would imply that the revised query has to still produce the same set of columns, else it's inconsistent with the MV's stored data (but maybe we could allow adding new columns at the end, as with tables). I suppose this means that if you want a different set of columns, you have no recourse short of dropping the MV. regards, tom lane