2012-02-22 19 views
2
select current_timestamp(6), current_timestamp(0) 
---------------------------------------------------- 
2012-02-22 16:03:45.988418+13 | 2012-02-22 16:03:46+13 
      -------^     ------------^ (date from the future) 

由於current_timestamp(0)正在「數學」舍入,此查詢可以很容易地從第二列的未來返回時間戳。這可能會導致一些意想不到的錯誤,這是因爲檢索時間從未來到0.5秒。第二個地板時間戳

所以我的問題是 - 將current_timestamp(6)四捨五入到最近的第二個最簡單的方法是什麼?

PS:我知道有轉換爲秒和背面

PPS溶液:結果應該是時間戳類型,而不是字符串

UPD

實測值的溶液

select current_timestamp(6), current_timestamp(0)::abstime 

回答

3
select current_timestamp(6), date_trunc('second', current_timestamp(6))