PostgreSQL查询当前时间的时间戳

一、问题

  使用PostgreSQL获取当前系统时间戳。众所周知,在MySQL中是这样的:

   select UNIX_TIMESTAMP(NOW())

二、解决方案

(1)精确到秒

  select floor(extract(epoch from now())); 结果:"1574826646"

(2)精确到秒的小数

  select extract(epoch from now());结果:"1574826646.79929"

(3)精确到毫秒:

  select floor(extract(epoch from((current_timestamp - timestamp '1970-01-01 00:00:00')*1000)));
 

猜你喜欢

转载自www.cnblogs.com/songxingzhu/p/11941285.html