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 1g38Z2-0006NX-2N for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Sep 2018 23:40:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g38Z0-0003Z8-6e for pgsql-hackers@arkaria.postgresql.org; Thu, 20 Sep 2018 23:40:50 +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 1g38Yz-0003Yx-Us for pgsql-hackers@lists.postgresql.org; Thu, 20 Sep 2018 23:40:49 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1g38Ys-0002HC-QF for pgsql-hackers@postgresql.org; Thu, 20 Sep 2018 23:40:49 +0000 Received: from bruce by momjian.us with local (Exim 4.84_2) (envelope-from ) id 1g38Yq-0004U1-Ar for pgsql-hackers@postgresql.org; Thu, 20 Sep 2018 19:40:40 -0400 Date: Thu, 20 Sep 2018 19:40:40 -0400 From: Bruce Momjian To: PostgreSQL-development Subject: transction_timestamp() inside of procedures Message-ID: <20180920234040.GC29981@momjian.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This function shows that only clock_timestamp() advances inside a procedure, not statement_timestamp() or transaction_timestamp(): CREATE OR REPLACE PROCEDURE test_timestamp () AS $$ DECLARE str TEXT; BEGIN WHILE TRUE LOOP -- clock_timestamp() is updated on every loop SELECT clock_timestamp() INTO str; RAISE NOTICE 'clock %', str; SELECT statement_timestamp() INTO str; RAISE NOTICE 'statement %', str; SELECT transaction_timestamp() INTO str; RAISE NOTICE 'transaction %', str; COMMIT; PERFORM pg_sleep(2); END LOOP; END $$ LANGUAGE plpgsql; CALL test_timestamp(); NOTICE: clock 2018-09-20 19:38:22.575794-04 NOTICE: statement 2018-09-20 19:38:22.575685-04 NOTICE: transaction 2018-09-20 19:38:22.575685-04 --> NOTICE: clock 2018-09-20 19:38:24.578027-04 NOTICE: statement 2018-09-20 19:38:22.575685-04 NOTICE: transaction 2018-09-20 19:38:22.575685-04 This surprised me since I expected a new timestamp after commit. Is this something we want to change or document? Are there other per-transaction behaviors we should adjust? -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + As you are, so once was I. As I am, so you will be. + + Ancient Roman grave inscription +