Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YoCbG-0007sO-EV for pgsql-hackers@arkaria.postgresql.org; Fri, 01 May 2015 15:11:34 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YoCbF-0002hv-UV for pgsql-hackers@arkaria.postgresql.org; Fri, 01 May 2015 15:11:33 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YoCbE-0002ez-Pt for pgsql-hackers@postgresql.org; Fri, 01 May 2015 15:11:32 +0000 Received: from tamriel.snowman.net ([2001:4830:167b::11]) by makus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1YoCbC-000392-Ga for pgsql-hackers@postgresql.org; Fri, 01 May 2015 15:11:31 +0000 Received: by tamriel.snowman.net (Postfix, from userid 1000) id B60095F7AC; Fri, 1 May 2015 11:11:29 -0400 (EDT) Date: Fri, 1 May 2015 11:11:29 -0400 From: Stephen Frost To: Robert Haas Cc: Andres Freund , Peter Geoghegan , hlinnaka , Jeff Janes , Dean Rasheed , Bruce Momjian , Pg Hackers Subject: Re: INSERT ... ON CONFLICT UPDATE/IGNORE 4.0 Message-ID: <20150501151129.GI30322@tamriel.snowman.net> References: <20150501135800.GC22649@awork2.anarazel.de> <20150501141052.GE22649@awork2.anarazel.de> <20150501142403.GG22649@awork2.anarazel.de> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="MUgosN8HgFyWu2R6" Content-Disposition: inline In-Reply-To: X-Editor: Vim http://www.vim.org/ X-Info: http://www.snowman.net X-Operating-System: Linux/3.13.0-46-generic (x86_64) X-Uptime: 10:47:18 up 42 days, 20:35, 25 users, load average: 0.13, 0.11, 0.13 User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -0.4 (/) 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 --MUgosN8HgFyWu2R6 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline * Robert Haas (robertmhaas@gmail.com) wrote: > OK. In that case, I'm a lot less sure what the right decision is. It > seems weird for both the BEFORE INSERT and BEFORE UPDATE triggers to > get a crack at the same tuple, so your way might be better after all. > But on the other hand, the BEFORE INSERT trigger might have had side > effects, so we can't just pretend it didn't happen. I agree that having the before-insert and before-update triggers both fire is a bit odd, but I also think it's the right thing to do. If the statements were independent instead of an INSERT .. ON CONFLICT, then both sets of before triggers would very clearly fire. > One idea is to decide that an INSERT with an ON CONFLICT UPDATE > handler is still an INSERT. Period. So the INSERT triggers run, the > UPDATE triggers don't, and that's it. Another option would be to have an independent "INSERT-ON-CONFLICT" before trigger which fires.. but, for my 2c, I'm happy to just fire both. I definitely feel that the EXCLUDED tuple should refer to the post before-insert trigger; having it refer to a tuple that may not have actually conflicted doesn't seem correct to me. Thanks! Stephen --MUgosN8HgFyWu2R6 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBCgAGBQJVQ5ehAAoJEO1sijiDR2RVr7MQAL0+PSmRANqfkvLO5jvIoh6b yRnlGGzWqteys7bvVcVn3w3eoUaCDRMaMWnbK5FUC1CGA+Q12Gkzsd+fVpWjc54k 8CS3m/9jS7px7owYQV8GJkkb/9+5iZgUYt5spYpwp5HCycE5GVmYc2L0guFPN3qE qd134xZVwcg7CjFE6SRdEhzoBm6zFMNGgRyNfZzmDFYGepiVY2slDcJAb8XBxnFV Wt4tCyT4XTzvapEoKlKQKWkkvVyNet27hTN1hAfChQliGJzRAalf4dCqkHlxZ2zT iBrmbok7+w6Ojf047meOdqs+QvJbh1wmmLd4vIZbBVA63enOtrKbg2yx4WdXwtYE ONC/u8OBbWQDCbP+RWfR96+WGdkhhW2jDm+E8WLFKcVQLDbA1pUgmyPmp1RiPSoA pD0QGZPcUpl/oBp4r8EXJ2M1pKzhQe908UdtMbQ5ZoFIm1TYIhYDeBvxyksXxlzn asQArz46LPTOh3GESQ1XOiOiRDjPFYAl16xu9TEo0fXP83Rz7F5hdWJblPKN14m4 B592V5PLFLcV0UdH49vJ+slJkqhkjyxJ3UVSSsy3UfMujqflNykgQUckjU+yhptL 23A/TuHF0+Rbm19jHiqZDMS9QQsOjjZdSSD86mxtqWbW6L5oGf9eZnlfGWTEA2HY IzOYC4ejtr/qWooXpjEb =O9dw -----END PGP SIGNATURE----- --MUgosN8HgFyWu2R6--