Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g9bbO-0004Y0-0E for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Oct 2018 19:54:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g9bbM-0005en-AK for pgsql-hackers@arkaria.postgresql.org; Mon, 08 Oct 2018 19:54:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g9bbM-0005eg-3F for pgsql-hackers@lists.postgresql.org; Mon, 08 Oct 2018 19:54:00 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g9bbJ-0007oc-NB for pgsql-hackers@lists.postgresql.org; Mon, 08 Oct 2018 19:53:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w98Jrmph032764; Mon, 8 Oct 2018 15:53:48 -0400 From: Tom Lane To: Peter Eisentraut cc: pgsql-hackers@lists.postgresql.org, Andres Freund , PostgreSQL-development , Alvaro Herrera , Bruce Momjian , Michael Paquier Subject: Re: transction_timestamp() inside of procedures In-reply-to: References: <20180926155443.u4zh7jactzflys3z@alvherre.pgsql> <20181002145853.wvhcb7pbrzgjyxns@alap3.anarazel.de> <38e36919-8bee-c717-be99-91137ad28aaf@2ndquadrant.com> <27414.1539018874@sss.pgh.pa.us> Comments: In-reply-to Andres Freund message dated "Mon, 08 Oct 2018 10:24:56 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <32762.1539028428.1@sss.pgh.pa.us> Date: Mon, 08 Oct 2018 15:53:48 -0400 Message-ID: <32763.1539028428@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andres Freund writes: > On October 8, 2018 10:14:34 AM PDT, Tom Lane wrote: >> Surely there is some way that we can directly test whether we're inside >> a procedure or not? I think the logic should be basically >> ... > Seems more reasonable from here. We are rapidly running out of time to get this fixed before RC1. In the interests of getting across the finish line, I took a look around, and found that indeed there does not seem to be any exported way to detect whether we're inside a procedure or not. Which seems pretty darn dumb from here. The best way to determine that seems to be to check that that the SPI stack is (a) nonempty and (b) has a "nonatomic" topmost entry. Barring objections, I'm going to make a quick hack that adds a SPI entry point along the lines of "bool SPI_inside_nonatomic_context(void)" to do that test, adapt the xact.c code as I said upthread, and commit with Peter's regression test case. regards, tom lane