◈ 차이점
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초 만큼 쉬겠다는 의미입니다.
'DB' 카테고리의 다른 글
[DB] AWS vs. 애저 vs. 구글"··· 클라우드 무료 티어 비교 (0) | 2018.07.30 |
---|---|
[DB] 클라우드 DB 종류 (0) | 2018.07.30 |
[Oracle] WITH가 성능에 미치는 영향 (0) | 2018.07.03 |
[MSSQL] T-SQL 쿼리문 종류 (0) | 2018.07.03 |
[DB] Mssql, mysql, oraclem 차이 (0) | 2018.06.27 |