Now()
(當前時間)與您選擇的列替換:
select
-- current time
now(),
-- current time truncated to minutes
date_trunc('minute', Now()),
-- seconds from timestamp, including decimal part
extract(seconds from Now()),
-- seconds truncated to first decimal digit (results in seconds and decisecond)
trunc((extract(seconds from Now()))::numeric, 1),
-- add time truncated to minutes and seconds truncated to first decimal digit
date_trunc('minute', Now())
+ interval '1 second' * trunc((extract(seconds from Now()))::numeric, 1)
注意,轉換爲numeric
被要求作爲extract()
回報double precision
和trunc(x, y)
只接受numeric
(見documentation)
隨着列命名mytime
這將是:
date_trunc('minute', mytime)
+ interval '1 second' * trunc((extract(seconds from mytime))::numeric, 1)
另一種選擇是截斷epoch
:
select
-- current time
now(),
-- epoch - number of seconds since epoch beginning, including decimal part
extract(epoch from Now()),
-- truncated to first decimal digit
trunc((extract(epoch from Now()))::numeric, 1),
-- converted back to timestamp
to_timestamp(trunc((extract(epoch from Now()))::numeric, 1))
使用命名mytime
列,這將是:
to_timestamp(trunc((extract(epoch from mytime))::numeric, 1))
文檔:extract
,epoch
,to_timestamp