写一个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()记录的是实时时间。