Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1emOtp-00086p-5c for pgsql-general@arkaria.postgresql.org; Thu, 15 Feb 2018 19:08:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1emOtn-0005bo-RK for pgsql-general@arkaria.postgresql.org; Thu, 15 Feb 2018 19:08:51 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1emOtn-0005bf-Cz for pgsql-general@lists.postgresql.org; Thu, 15 Feb 2018 19:08:51 +0000 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1emOtj-0003SK-Ik for pgsql-general@lists.postgresql.org; Thu, 15 Feb 2018 19:08:49 +0000 Received: by mail-pg0-x242.google.com with SMTP id f6so498390pgs.10 for ; Thu, 15 Feb 2018 11:08:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=illuminatedcomputing-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-language:content-transfer-encoding; bh=Lu1a8Vlvwc81hdB3MPVk7ziDxctY/QFBAuyv9gqDin4=; b=HXv/pjT2p7vzA9UGWzQrN8v2sYa+wNEd8up1a1ixVRcONzKh8JHHyZvp39/gpTeyRx Mk0AYpYqse0Se8sPm7TLSwPE3CmUb59K+AHzlkSXXaKsD/UcLI0qCK4fjo+9a6/8Vtsb GlHX5Az+BC+oUo8Ok08iPXsa4BD74PCuiXIg2xaaWsFriGre3uxOtnwJKiMSJYCgwDzy r7fFPpAXZSnjYghpjXqfDEm8FykVVweHjr5LiGfl0uK6gDj2Jbw/LGFmsRfAQL+LpvP5 vIIu4KKBOEQtTjyt9OsInxJEs/i9vEM4euH+8TtBwX6UBGP7yKPOPhGhi4m9yHd+gKjv Zwwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Lu1a8Vlvwc81hdB3MPVk7ziDxctY/QFBAuyv9gqDin4=; b=eM4SKohxyJVfxYVYo/8FshV1sywKo2LxCsKg88YpFf/is9x733KaNWaL9AKKhsQAkQ MKKJdhbSBtC619CJhWb+OSN5+YlDBlnQTwewrx5OoiXRf4/6qaEWlnI0UyeUKFoKoMZO sCsFpNaYBOPxsPEUm3dkw2X7Lupz2JgVaZ78Nj+3EPQEWgEyY42qYMV/0Go0Co34E2xp pOK5oIKNSMHbaX+QBn32P9HthN+YwZL8wlekT1SXXFEpQL33KOURiUN6WEgdKwjCVeSh ui+WtsCC5Qs1DzyOp/VQ9+LzYRV7ANWYwMINvlSSU3xugIQjESJr7x28e8jNyj69M61i EWmA== X-Gm-Message-State: APf1xPBGSD87L3nxZyIA5w03T2aYWryKS0Wd4VOEUoG0AeqNYarFfJVb l14yf3Xxl3ZoTmYshcuAHOyyfQxQ X-Google-Smtp-Source: AH8x225+EGnpDzByh9LAw6E06q6btrSNGFJ15MlYVl/4Bjrv5DCyFLRXR6435UxxFe2WcsWg6LpZ0Q== X-Received: by 10.98.88.1 with SMTP id m1mr3593605pfb.178.1518721725681; Thu, 15 Feb 2018 11:08:45 -0800 (PST) Received: from [192.168.2.201] (static-50-53-109-254.bvtn.or.frontiernet.net. [50.53.109.254]) by smtp.googlemail.com with ESMTPSA id y16sm28007502pfl.79.2018.02.15.11.08.44 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Feb 2018 11:08:44 -0800 (PST) Subject: Re: Trigger (or something similar) on table rename? To: pgsql-general@lists.postgresql.org References: From: Paul Jungwirth Message-ID: <261abb38-4c77-becf-fc1e-8bd7eee1445b@illuminatedcomputing.com> Date: Thu, 15 Feb 2018 11:08:43 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 02/15/2018 10:52 AM, Ken Tanzer wrote: > Hi.  I'm wondering about possibilities for taking action when a table is > renamed. I've looked into this a bit. Here is what I understand: Since 9.3 Postgres has had "event triggers" which can run code on DDL events (https://www.postgresql.org/docs/current/static/event-triggers.html). There are events like `ddl_command_start` and tags like `ALTER TABLE`. So you could write a trigger that fires `ON ddl_command_start WHEN TAG IN ('ALTER TABLE')`. Unfortunately I don't think you can get the old/new table name from inside the trigger function. If you need that, you might take a look at this extension which adds some custom event triggers with ways of getting that information: https://github.com/CartoDB/pg_schema_triggers If you are really adventurous you could even look at using the ProcessUtility hook directly to do what you need. I'm looking forward to seeing what others say here because I'd like to know more myself! Good luck! -- Paul ~{:-) pj@illuminatedcomputing.com