PostgreSQL 时间函数的比较

前端之家收集整理的这篇文章主要介绍了PostgreSQL 时间函数的比较前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

写一个function来测试比较:

do

$$
declare
begin
for i in 1.. 20 loop
raise notice 'time1:%,time2:%,time3:%,time4:%',localtimestamp,current_timestamp,now(),clock_timestamp() ;
end loop;
end;
$$;

postgres=# do
postgres-# $$
postgres$# declare
postgres$# begin
postgres$# for i in 1.. 20 loop
postgres$# raise notice 'time1:%,clock_timestamp() ;
postgres$# end loop; 
postgres$# end;
postgres$# $$;
NOTICE:  time1:2015-03-11 09:00:00.440075,time2:2015-03-11 09:00:00.440075+08,time3:2015-03-11 09:00:00.440075+08,time4:2015-03-11 09:00:00.442224+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.442269+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.442291+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.442311+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.442336+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.442356+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.442376+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.442395+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.442416+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.442833+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.442881+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.442906+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.442926+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.442945+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.442965+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.442986+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.443009+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.443029+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.443048+08
NOTICE:  time1:2015-03-11 09:00:00.440075,time4:2015-03-11 09:00:00.44307+08
DO
该循环是一个事务,可以看出localtimestamp,now()三者记录的都是事务的开始时间,只有clock_timestamp()记录的是实时时间。


参考:http://www.07net01.com/2014/09/135111.html

原文链接:https://www.f2er.com/postgresql/195329.html

猜你在找的Postgre SQL相关文章