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 1jYIhY-0002cI-F2 for pgsql-general@arkaria.postgresql.org; Tue, 12 May 2020 00:23:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jYIhX-0007bU-BQ for pgsql-general@arkaria.postgresql.org; Tue, 12 May 2020 00:23:15 +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 1jYIhW-0007b9-W6 for pgsql-general@lists.postgresql.org; Tue, 12 May 2020 00:23:15 +0000 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jYIhS-0005X6-Sq for pgsql-general@lists.postgresql.org; Tue, 12 May 2020 00:23:14 +0000 Received: by mail-qk1-x742.google.com with SMTP id f13so11318958qkh.2 for ; Mon, 11 May 2020 17:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=uI2BrSjGoZHBYJkXEtfKREd85Gm90yFuequTiEr9oZc=; b=VYW89j5a20y5TrVhSfOVU20VPlBBm82qdXZZHXOITtJEPUvewcMuNrVovHgo/NVWxX ekF4o99pHLaEHULNzlaP8mbvMPoVr9LzHGWt5GxCMf1cOb71vzgnr3/0/PwomgmTYC/s mVakNoyFyxAC9MZDawxduDYel6OyoFHYcnxRVggX9vuysjBIo8zl7wR9QmwY9beoiOZH rsLohBRMZBbf0PLXZeRMyAoJ4LrnV6FHj8Aj9oo/HxwqWx1D/iGiaqGPafkAWZwwmccA GXlSsWGfvJjeQB9ipVTh6gskagRNqOFCQxJ8+k5zi7QgLeO7HAxZysRD8dy0DKmwcLyB W53w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=uI2BrSjGoZHBYJkXEtfKREd85Gm90yFuequTiEr9oZc=; b=pXBpHnPFBBWSq0Mm63ze5XHrqQqVr2j76lrvIxOrZB/cHAJxnqOgzbMVSqhGniRe2V q038cgFvHzT5+b/O/eR96WFNIcRO+7fjcBMRxt/rqVZ1gNWbHoFPzJA9jhdyzQT13JI4 o92TRBiY00azFGgf0vFC5BxkgCGREDYbMEgp7SGX/c6EXPbDPeC9WthnH20WikkxRbjH vXYAyrZW9W4uqADz7yWJyuxv8Xw+KUSP8lVikrQtf5kqZc6kk9C4oVGxsQa8oi/rgp35 cVtyFGRMo/svQjtEnpIEgoQeyT6dQBDEmybW6XyPJYSLJzTa734S5Uk9bjAOxB9oEbU+ KJgg== X-Gm-Message-State: AGi0PubkzfHrBgjOXhKNeNpN51/xjIx0JpXYn3kR5wpyCGmRh7F1x20v kfBx3wvbMHAubGNez9XmAWnWEw== X-Google-Smtp-Source: APiQypJhXlTvGaUu+T9WMaCYqUx4W9TzLmPCHXpWklCUL0mTLXCiG8p1RhdR9CizHf40n+y3iuargQ== X-Received: by 2002:a37:a008:: with SMTP id j8mr17720698qke.421.1589242989093; Mon, 11 May 2020 17:23:09 -0700 (PDT) Received: from nimloth.alvh.no-ip.org ([190.95.18.252]) by smtp.gmail.com with ESMTPSA id o16sm9959144qko.38.2020.05.11.17.23.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 May 2020 17:23:08 -0700 (PDT) Received: by nimloth.alvh.no-ip.org (Postfix, from userid 1000) id CD82A3002F7; Mon, 11 May 2020 20:23:05 -0400 (-04) Date: Mon, 11 May 2020 20:23:05 -0400 From: Alvaro Herrera To: Michel Pelletier Cc: pgsql-general Subject: Re: Firing an event trigger for ADD COLUMN? Message-ID: <20200512002305.GA28510@alvherre.pgsql> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020-May-11, Michel Pelletier wrote: > Is this asymmetry a bug? I realize these event trigger functions are > typically written in C, but I'd like to keep this idea contained to a > plpgsql function and cover as many reversible changes as I can. Sadly, you cannot obtain all the necessary details using only plpgsql. The only way is to compile a C extension. There's a very rough, incomplete skeleton to show how to do this in src/test/modules/test_ddl_deparse. A much more complete approach, which was not completed, was used to produce JSON output from the C structures -- see https://www.postgresql.org/message-id/20150409161419.GC4369@alvh.no-ip.org Keep in mind ALTER TABLE is a very sophisticated; you can do things like ALTER TABLE one ADD COLUMN two INT, DROP COLUMN three, ADD COLUMN four text; (i.e. do several things in one command) so if you were to use a simplistic approach, you might end up missing things. -- Álvaro Herrera https://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services