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() 시간만 변경됩니다. 정확한 시간을 사용하라면 이 값을 사용.