如何在postgresQL中将时间从文本转换为时间格式?

时间:2018-08-14 05:30:09

标签: postgresql pgadmin

我已经在PostgreSQL中完成了此查询:

select b.movement_category, 
round(count(*)*100/case when count(*) = 0 then 1 else sum(count(*)) over () end::numeric,2) cnt_pct
from ( 
select distinct a.imei_number, a.movement_category
from dataview a
where a.data_capture_time between '2018-07-28' and '2018-07-28'
and a.movement_category <> ''
and fn_distance_km(23.728264,90.411367,cast(a.latitude as double precision),cast(a.longitude as double precision))<=20
) b                
group by b.movement_category

1 个答案:

答案 0 :(得分:1)

看看documentation的格式化函数,该函数可以转换各种数据类型。

您的情况的一个示例可能是:

SELECT to_timestamp('05 Dec 2000 15:15:20', 'DD Mon YYYY HH24:MI:SS')::TIME

这将返回15:15:20