Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YoBrT-0005Jv-MD for pgsql-hackers@arkaria.postgresql.org; Fri, 01 May 2015 14:24:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YoBrS-0006Aj-Ue for pgsql-hackers@arkaria.postgresql.org; Fri, 01 May 2015 14:24:15 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YoBrP-00064y-Mr for pgsql-hackers@postgresql.org; Fri, 01 May 2015 14:24:11 +0000 Received: from mail.anarazel.de ([217.115.131.40]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1YoBrN-0002ae-6H for pgsql-hackers@postgresql.org; Fri, 01 May 2015 14:24:10 +0000 Received: by mail.anarazel.de (Postfix, from userid 108) id 19716860001; Fri, 1 May 2015 16:24:08 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on mail X-Spam-Level: X-Spam-Status: No, score=-4.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from anarazel.de (p54895C9D.dip0.t-ipconnect.de [84.137.92.157]) (Authenticated sender: andres@anarazel.de) by mail.anarazel.de (Postfix) with ESMTPSA id 97D36860002; Fri, 1 May 2015 16:24:04 +0200 (CEST) Received: by anarazel.de (Postfix, from userid 1000) id E698A100C30; Fri, 1 May 2015 16:24:03 +0200 (CEST) Date: Fri, 1 May 2015 16:24:03 +0200 From: Andres Freund To: Robert Haas Cc: Peter Geoghegan , hlinnaka , Jeff Janes , Stephen Frost , Dean Rasheed , Bruce Momjian , Pg Hackers Subject: Re: INSERT ... ON CONFLICT UPDATE/IGNORE 4.0 Message-ID: <20150501142403.GG22649@awork2.anarazel.de> References: <20150501135800.GC22649@awork2.anarazel.de> <20150501141052.GE22649@awork2.anarazel.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 2015-05-01 10:21:27 -0400, Robert Haas wrote: > On Fri, May 1, 2015 at 10:10 AM, Andres Freund wrote: > > On 2015-05-01 10:06:42 -0400, Robert Haas wrote: > >> On Fri, May 1, 2015 at 9:58 AM, Andres Freund wrote: > >> > would you rather have EXCLUDED.data refer to the tuple version from > >> > VALUES (or a SELECT or ...) or to version from the BEFORE trigger? > >> > >> I think it would be completely shocking if it didn't refer to the > >> version returned by the BEFORE trigger. My interpretation of the > >> semantics of BEFORE triggers is that, once the trigger has fired and > >> returned a new tuple, things should proceed just as if that new tuple > >> were the one originally provided by the user. > > > > Well, it's a BEFORE INSERT trigger, not a BEFORE UPDATE, that's why I'm > > not so sure that argument applies. > > Would the BEFORE UPDATE trigger even fire in this case? BEFORE UPDATE triggers fire for INSERT ... ON CONFLICT UPDATE iff there's a conflict, yes. > The thing is, suppose somebody puts a BEFORE INSERT trigger and a > BEFORE UPDATE trigger on the table, and each of those triggers does > this: > > NEW.last_updated_time = clock_timestamp(); > return NEW; > > That should work, and should cover all cases, even if you're using UPSERT. The BEFORE UPDATE would catch things in this case. Greetings, Andres Freund -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers