Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mvLwq-0004od-P5 for pgsql-general@arkaria.postgresql.org; Thu, 09 Dec 2021 16:07:08 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1mvLwJ-0007XT-Sv for pgsql-general@arkaria.postgresql.org; Thu, 09 Dec 2021 16:06:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mvLwJ-0007XK-HY for pgsql-general@lists.postgresql.org; Thu, 09 Dec 2021 16:06:35 +0000 Received: from zimbabwe.chezphil.org ([34.255.138.49]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mvLwD-0001Km-B8 for pgsql-general@lists.postgresql.org; Thu, 09 Dec 2021 16:06:35 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=chezphil.org mappendix.com; s=20171026; h=From:Content-Type:MIME-Version: References:In-Reply-To:Message-ID:Subject:Date:To:Sender:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=vLLH8E3hyyz1Klja2xtuHt3W+HUtOVrOf7ScDdFzwvk=; b=ZfKb4lQw28aiVD3TVaUmjOQ4/K qTaw0LjTfMIWLKO4F2wrEokI1ZTeWppKG9d7imAgrR8sbUi5rzCcnTKjRo2Kts/j1HGD28AXWNShn vO5cGTREmTfzilFjtz2SmOFJdW2eduQ6/jQLC5Ezn5BnG/ZHLjsq126jBDbVzbdSTWWY=; Received: from localhost ([127.0.0.1] helo=chezphil.org) by zimbabwe.chezphil.org with esmtp (Exim 4.94.2) (envelope-from ) id 1mvLwC-00EGoE-5n for pgsql-general@lists.postgresql.org; Thu, 09 Dec 2021 16:06:28 +0000 Received: from localhost ([::ffff:127.0.0.1]) by zimbabwe with smtp (dmsmtpd 0.00001); Thu, 09 Dec 2021 16:06:28 +0000 To: Date: Thu, 09 Dec 2021 16:06:27 +0000 Subject: Re: Advice on using materialized views Message-ID: <1639065987898@dmwebmail.dmwebmail.chezphil.org> In-Reply-To: <20211207103251.59354436@tipi> References: <20211207103251.59354436@tipi> X-Mailer: Decimail Webmail 3alpha16 MIME-Version: 1.0 Content-Type: text/plain; format="flowed"; charset="UTF-8" From: "Phil Endecott" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Thanks both for your replies. Wicher wrote: > On Mon, 06 Dec 2021 18:48:47 +0000 > "Phil Endecott" wrote: >> and >> I need to modify the definition of a view that filters the "new" >> values from the raw table each time the materialised view is >> refreshed. > > You won't necessarily need to rewrite the "recent data" view definitions, I think. What is > deemed "recent" depends on what's in the materialized views (it'd be anything newer than > whatever is in there). The good news is that you can simply query for that :-) > So trivially, in your "the data that is more recent than the stuff from the materialized > views" non-materialized view you'd use a definition like > SELECT .... WHERE sometimestamp > (select max(sometimestamp) from the_materialized_view) > or something along those lines. I guess I was hoping that someone would suggest a more "magic" way to do this sort of thing. Actually I'm a bit surprised that materialised views don't event have a way to either - Refresh a materialised view whenever a source table is modified; - Refresh a materialised view whenever it is read, if a source table has changed since it was last refreshed. Beyond that, I could imagine smart updates where e.g. if you modify source table rows with primary key K, then you only need to refresh materialised view rows derived from K. I think this could all be done on top of triggers. I wonder, do any other databases do things like this automagically? Regards, Phil.