健康一贴灵,专注医药行业管理信息化

pgsql 关于时间戳的

-- 计算当前时间戳
SELECT right(cast(floor(extract(epoch from now())*1000)/cast(telephone as dec) as varchar),6) from wechat_person
--当前时间戳除以7,转换为字符串,取右6位
SELECT right(cast(floor(extract(epoch from now())*1000)/cast(7as dec) as varchar),6) 

SELECT floor(extract(epoch from now())*1000)/3 AS last_modified_time;

-- 经过在线验证的准确写法
SELECT floor(extract(epoch from now()))*1000 AS last_modified_time;  -- 先取整后乘以1000会丢失精度,太粗糙
SELECT extract(epoch from now()) AS last_modified_time;  -- 小数点后有5位小数
SELECT extract(epoch from now())*1000 AS last_modified_time;  -- 小数点后有两位小数
SELECT floor(extract(epoch from now())*1000) AS last_modified_time;  -- 向下取整,无小数
SELECT extract(epoch from now())*1000 AS t1, floor(extract(epoch from now())*1000) AS t2;  -- t1有小数,t2无小数

 

posted @ 2023-02-17 14:15  一贴灵  阅读(210)  评论(0编辑  收藏  举报
学以致用,效率第一