본문 바로가기

DB

[PGSQL] now(), clock_timestamp(), current_timestamp 차이

◈ 차이점 

now()                  

timestamp with time zone Current date and time (start of current transaction); see Section 9.9.4

clock_timestamp()

timestamp with time zone Current date and time (changes during statement execution : 명령문 실행

변경); see Section 9.9.4

current_timestamp

timestamp with time zone Current date and time (start of current transaction); see Section 9.9.4

 

 - now current_timestamp 동의어 입니다

 - Now current_timestamp 트랜잭션이 시작되는 시간을 그대로 유지합니다. 트랜잭션내에서 실제 입력이나 변화되는 시간을 

찍고 싶으면Clock_timestamp 사용하면 .

 

select now()

select clock_timestamp()

select current_timestamp

 

now(), clock_timestamp(), current_timestamp

 

now()                   timestamp with time zone Current date and time (start of current transaction); see Section 9.9.4

clock_timestamp() timestamp with time zone Current date and time (changes during statement execution); see Section 9.9.4

current_timestamp timestamp with time zone Current date and time (start of current transaction); see Section 9.9.4

 

 

  • 예제

일단 아래 a.sql 을 음미해보세요.

 

$> cat a.sql

 

 

select now(), current_timestamp, timeofday();

 

select pg_sleep(1);

 

select now(), current_timestamp, timeofday();

 

begin;

 

select now(), current_timestamp, timeofday();

 

select pg_sleep(1);

 

select now(), current_timestamp, timeofday();

 

select pg_sleep(1);

 

select now(), current_timestamp, timeofday();

 

rollback;

 

select now(), current_timestamp, timeofday();

 

select pg_sleep(1);

 

select now(), current_timestamp, timeofday();

 

$>

 

-- now() current_timestamp 는 동의어입니다.

 

-- pg_sleep(1) 1초 만큼 쉬겠다는 의미입니다.