Re: transction_timestamp() inside of procedures

From: Andres Freund <andres(at)anarazel(dot)de>
To: Bruce Momjian <bruce(at)momjian(dot)us>, Peter Eisentraut <peter_e(at)gmx(dot)net>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: transction_timestamp() inside of procedures
Date: 2018-09-25 21:50:02
Message-ID: 20180925215002.lswusijvntmbc46y@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2018-09-20 19:40:40 -0400, Bruce Momjian wrote:
> 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?

ISTM this is an issue that belongs on the open items list. Peter, could
you comment?

Greetings,

Andres Freund

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Saheed Bolarinwa 2018-09-25 21:54:03 Please, can I be a mentor for Google Code In
Previous Message Chapman Flack 2018-09-25 21:47:21 clarify documentation of BGW_NEVER_RESTART ?