How to get a real time within PostgreSQL transaction?

后端 未结 3 1173
被撕碎了的回忆
被撕碎了的回忆 2021-01-01 11:14

As far as I understand now() returns the same time during the whole PostgreSQL transaction? But how to get real time?

Also, I am interested

3条回答
  •  孤城傲影
    2021-01-01 11:57

    To limit the time of a statement (not a transaction) you can use statement_timeout. now() will increment on each execution if not within a transaction block. Thus:

    postgres=# select now();
                  now              
    -------------------------------
     2010-08-11 13:44:36.207614-07
    (1 row)
    
    postgres=# select now();
                  now              
    -------------------------------
     2010-08-11 13:44:36.688054-07
    (1 row)
    
    postgres=# select now();
                  now              
    -------------------------------
     2010-08-11 13:44:40.407623-07
    (1 row)
    
    postgres=# begin;
    BEGIN
    postgres=# select now();
                  now              
    -------------------------------
     2010-08-11 13:44:43.417611-07
    (1 row)
    
    postgres=# select now();
                  now              
    -------------------------------
     2010-08-11 13:44:43.417611-07
    (1 row)
    
    postgres=# 
    

提交回复
热议问题