postgresql 时间戳格式为5分钟、15分钟

select case fmt
when '15 min' then (date_trunc('hour', val) + date_part('minute', val)::int / 15 * interval '15 min')
when '30 min' then (date_trunc('hour', val) + date_part('minute', val)::int / 30 * interval '30 min')
when '5 min' then (date_trunc('hour', val) + date_part('minute', val)::int / 5 * interval '5 min')
else date_trunc(fmt, val) end;

posted @ 2017-02-04 11:32  haitlee  阅读(3382)  评论(0)    收藏  举报