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 1p5AL2-0000jY-TP for pgsql-general@arkaria.postgresql.org; Tue, 13 Dec 2022 18:49:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p5AL1-00055V-PM for pgsql-general@arkaria.postgresql.org; Tue, 13 Dec 2022 18:49:11 +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 1p5AL1-00055L-Ev for pgsql-general@lists.postgresql.org; Tue, 13 Dec 2022 18:49:11 +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 1p5AKz-0003iZ-C0 for pgsql-general@postgresql.org; Tue, 13 Dec 2022 18:49:10 +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 2BDIn7Kw2448384; Tue, 13 Dec 2022 13:49:07 -0500 From: Tom Lane To: Michel Pelletier cc: pgsql-general Subject: Re: Is there a way to detect that code is inside CREATE EXTENSION? In-reply-to: References: Comments: In-reply-to Michel Pelletier message dated "Tue, 13 Dec 2022 10:39:19 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2448382.1670957347.1@sss.pgh.pa.us> Date: Tue, 13 Dec 2022 13:49:07 -0500 Message-ID: <2448383.1670957347@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Michel Pelletier writes: > I'm working with an event trigger that fires on ALTER TABLE and regenerates > certain objects, but unfortunately those objects end up being owned by any > extensions that run ALTER TABLE and any subsequent alterations fail to > regenerate because they are owned by that extension. > Ideally, I'd like to be able to detect inside my trigger if I'm being > called from CREATE EXTENSION or not, but I can't find any obvious way to > detect that. At the C-code level you can check the creating_extension global variable, or maybe better look at the in_extension fields of CollectedCommands. I don't think we expose that state at the SQL level, but it's pretty hard to make a useful event trigger without writing any C ... regards, tom lane