pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruce Momjian <bruce@momjian.us>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: transction_timestamp() inside of procedures
Date: Thu, 20 Sep 2018 19:40:40 -0400
Message-ID: <20180920234040.GC29981@momjian.us> (raw)

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  <bruce@momjian.us>        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 +




view thread (32+ messages)  latest in thread

Message-ID: <20180920234040.GC29981@momjian.us>
Permalink:  ../20180920234040.GC29981@momjian.us/
Also on:    postgresql.org/message-id/20180920234040.GC29981@momjian.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: bruce@momjian.us
  Subject: Re: transction_timestamp() inside of procedures
  In-Reply-To: <20180920234040.GC29981@momjian.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox