PG에서 Current Time 정확하게 사용하기 0 2 2,763

by 지현명 [PostgreSQL 노하우/팁/자료] current time [2016.11.14 15:07:26]


--https://www.postgresql.org/docs/current/static/functions-datetime.html
--9.9.4. Current Date/Time

CREATE TABLE public.time_test (
  now VARCHAR,
  "current_timestamp" VARCHAR,
  clock_timestamp VARCHAR,
  transaction_timestamp VARCHAR,
  statement_timestamp VARCHAR
) ;

--------------------------
--Anonymous Block plpgsql
--------------------------

dO $$
BEGIN
   FOR counter IN 1..10 LOOP --for문에서 사용하는 변수는 선언하지 않아도 된다.
 perform  pg_sleep(1); --1 sec Stop
    insert into time_test
 select
     now(), --Current date and time (start of current transaction);
        current_timestamp, -- Current date and time (start of current transaction);
        clock_timestamp(), --Current date and time (changes during statement execution);
        transaction_timestamp(), -- Current date and time (start of current transaction);
        statement_timestamp(); -- Current date and time (start of current statement);

  RAISE NOTICE 'Counter: %', counter;
   END LOOP;
END; $$

select * from time_test;

트랜잭션내에서 clock_timestamp() 시간만 변경됩니다. 정확한 시간을 사용하라면 이 값을 사용.

 

by 주킹 [2017.02.15 17:15:52]

oracle 호환성 version인 EDB-PAS는

current_timestamp도 트랜잭션내에서 변동되도록 의도적으로 변경하였습니다. (참고하세요~)


by 지현명 [2017.11.08 10:12:28]

답변감사합니다.~^^

EDB-PAS는 라이선스가 없어서 테스트를 못해 봤습니다.

댓글등록
SQL문을 포맷에 맞게(깔끔하게) 등록하려면 code() 버튼을 클릭하여 작성 하시면 됩니다.
로그인 사용자만 댓글을 작성 할 수 있습니다. 로그인, 회원가입