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 1opt6t-0006j8-Ai for pgsql-general@arkaria.postgresql.org; Tue, 01 Nov 2022 15:23:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1opt6r-0005Q7-Sn for pgsql-general@arkaria.postgresql.org; Tue, 01 Nov 2022 15:23:25 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1opt6r-0005Py-IA for pgsql-general@lists.postgresql.org; Tue, 01 Nov 2022 15:23:25 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1opt6p-0007pV-AI for pgsql-general@postgresql.org; Tue, 01 Nov 2022 15:23:24 +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 2A1FNImp1181454; Tue, 1 Nov 2022 11:23:18 -0400 From: Tom Lane To: Adrian Klaver cc: =?UTF-8?B?6buE5a6B?= , pgsql-general@postgresql.org Subject: Re: Delete a table automatic? In-reply-to: References: Comments: In-reply-to Adrian Klaver message dated "Tue, 01 Nov 2022 07:35:10 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1181452.1667316198.1@sss.pgh.pa.us> Content-Transfer-Encoding: 8bit Date: Tue, 01 Nov 2022 11:23:18 -0400 Message-ID: <1181453.1667316198@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Adrian Klaver writes: > On 10/31/22 18:44, 黄宁 wrote: >> I now have two tables named A and B. Table B is calculated based on the >> data of table A. I wonder if table B can be automatically deleted when >> table A is deleted? > The only thing I can think of is a sql_drop event trigger: I wonder whether the OP's purposes wouldn't be better served by making B a view or materialized view, instead of a separate table. Then the cascaded-drop behavior would be automatic. regards, tom lane