我一直在努力解决这个问题。我有一个表名称开头和结束的表。我需要一个Postgres查询以一种很好的格式将时间传回给我。
原始(小时前)查询是
select * from public.volass
where linkedass=$request_id
order by start
所以当我尝试使用DiffDate时,我看起来像
select datediff(hours,start,finish), * from public.volass
where linkedass=$request_id
order by start
Postgres然后给我以下错误。
ERROR: column "hours" does not exist
LINE 1: select datediff(hours,start,finish), * from public.volass
^
********** Error **********
ERROR: column "hours" does not exist
SQL state: 42703
Character: 17
答案 0 :(得分:1)
考虑使用Postgre的EXTRACT:
SELECT (EXTRACT(EPOCH FROM finish - start) / 3600) AS duration, *
FROM public.volass
WHERE linkedass=$request_id
ORDER BY start