pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Holger Jakobs <holger@jakobs.com>
To: pgsql-admin <pgsql-admin@postgresql.org>
Subject: now() and statement_timestamp()
Date: Thu, 27 May 2021 18:26:42 +0200
Message-ID: <536812b3-8040-371d-506d-266bcf10ec2f@jakobs.com> (raw)

According to the documentation. now() should yield the timestamp of the 
current transaction, while statement_timestamp() should yield the 
timestamp of the current statement.

In case of Autocommit, both should be identical, in case of a running 
transaction, they should be different.

Funny enough, psql and executing the same statement from within an 
application yield different results. I tried a Tcl script and DBeaver.

Statement: |SELECT now(), statement_timestamp();|

psql: |2021-05-07 13:31:10.135851+02 | 2021-05-07 13:31:10.135851+02|

DBeaver: |2021-05-07 13:31:00.633784+02|2021-05-07 13:31:00.633913+02|

Tcl script: |{now {2021-05-07 13:24:54.659837+02} statement_timestamp 
{2021-05-07 13:24:54.65985+02}}|

So in psql now() and statement_timestamp() are identical when not in a 
transaction, while in the others the two values vary a little bit, 
roughly 100 microseconds.

How come the same statements aren't behaving identical. I'm using a 
current PostgreSQL server on a Linux machine.

-- 
Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012

Attachments:

  OpenPGP_signature (application/pgp-signature, 202B) download

view thread (3+ messages)  latest in thread

Message-ID: <536812b3-8040-371d-506d-266bcf10ec2f@jakobs.com>
Permalink:  ../536812b3-8040-371d-506d-266bcf10ec2f@jakobs.com/
Also on:    postgresql.org/message-id/536812b3-8040-371d-506d-266bcf10ec2f@jakobs.com

 · 

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-admin@postgresql.org
  Cc: holger@jakobs.com
  Subject: Re: now() and statement_timestamp()
  In-Reply-To: <536812b3-8040-371d-506d-266bcf10ec2f@jakobs.com>

* 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