Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WcmZ5-0003ZM-7o for pgsql-performance@arkaria.postgresql.org; Wed, 23 Apr 2014 02:05:35 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WcmZ4-0006QP-LT for pgsql-performance@arkaria.postgresql.org; Wed, 23 Apr 2014 02:05:34 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WcPK5-0001yn-Pi for pgsql-performance@postgresql.org; Tue, 22 Apr 2014 01:16:33 +0000 Received: from tux.ds.adp.com ([198.133.214.248]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WcPJz-0004mT-Tf for pgsql-performance@postgresql.org; Tue, 22 Apr 2014 01:16:32 +0000 Received: from chemo.hoffman.ds.adp.com (chemo [139.126.12.166]) by tux.ds.adp.com (8.13.8/8.13.8) with SMTP id s3M1GQGR005188 for ; Mon, 21 Apr 2014 20:16:26 -0500 Received: from (unknown [139.126.225.26]) by chemo.hoffman.ds.adp.com with smtp id 3f58_7619_b9be5450_c9bb_11e3_8395_001e670eca5a; Tue, 22 Apr 2014 01:16:25 +0000 Received: from DSXFE5HE.ds.ad.adp.com ([139.126.128.172]) by dsgsoint2he.hoffman.ds.adp.com (RSA Interceptor) for ; Mon, 21 Apr 2014 20:16:15 -0500 Received: from DSXMBX3HE.ds.ad.adp.com ([139.126.128.70]) by DSXFE5HE.ds.ad.adp.com ([139.126.128.79]) with mapi id 14.03.0181.006; Mon, 21 Apr 2014 20:16:15 -0500 From: "Verghese, Riya" To: "pgsql-performance@postgresql.org" Subject: Best practices for update timestamp with/without triggers Thread-Topic: Best practices for update timestamp with/without triggers Thread-Index: AQHPXch0QVHSRIw+DUKgAmsJa8P+IQ== Date: Tue, 22 Apr 2014 01:16:15 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: user-agent: Microsoft-MacOutlook/14.3.9.131030 x-originating-ip: [139.126.128.141] Content-Type: multipart/alternative; boundary="_000_CF7B10ED4EEE2rverghesecobaltcom_" MIME-Version: 1.0 X-Pg-Spam-Score: -1.5 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org --_000_CF7B10ED4EEE2rverghesecobaltcom_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-NAIMIME-Disclaimer: 1 X-NAIMIME-Modified: 1 Hi I am going to add a new column to a table for modify_date that needs to b= e updated every time the table is updated. Is it better to just update ap= plication code to set the modify_date to current_time, or create a Before= -Update trigger on the table that will update the modify_date column to c= urrent_timestamp when the table is updated? I also have slony in place, s= o the trigger will need to be on master and slave. Slony will take care o= f suppressing it on the slave and enabling in the event of a switchover, = but it is additional overhead and validation to make sure nothing failed = on switchover. So considering that we have slony, is it better to use application code t= o update the modify_date or use a trigger?Is a trigger essentially 2 upda= tes to the table? Are there any other risks in using the trigger? Thanks Riya Verghese This message and any attachments are intended only for the use of the add= ressee and may contain information that is privileged and confidential. I= f the reader of the message is not the intended recipient or an authorize= d representative of the intended recipient, you are hereby notified that = any dissemination of this communication is strictly prohibited. If you ha= ve received this communication in error, please notify us immediately by = e-mail and delete the message and any attachments from your system. --_000_CF7B10ED4EEE2rverghesecobaltcom_ Content-Type: text/HTML; charset="utf-8" Content-ID: Content-Transfer-Encoding: base64 X-NAIMIME-Disclaimer: 1 X-NAIMIME-Modified: 1 PGh0bWw+CjxoZWFkPgo8bWV0YSBodHRwLWVxdWl2PSJDb250ZW50LVR5cGUiIGNvbnRlbnQ9InRl eHQvaHRtbDsgY2hhcnNldD11cy1hc2NpaSI+CjwvaGVhZD4KPGJvZHkgc3R5bGU9IndvcmQtd3Jh cDogYnJlYWstd29yZDsgL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