15

我有这个问题。我有一个 sql 查询正在尝试对我的 postgres 数据库进行。这些查询在 oracle 中运行良好,但正在将其转换为 postgres 查询,但它会抱怨。这是查询:

select  to_char(calldate,'Day') as Day, date_trunc(calldate) as transdate,
Onnet' as destination,ceil(sum(callduration::integer/60) )as    total_minutes,round(sum(alltaxcost::integer) ,2)as revenue
from cdr_data 
where callclass ='008' and callsubclass='001'
and callduration::integer >0
and  regexp_like(identifiant,'^73')
and bundleunits = 'Money'
and inserviceresultindicator in (0,5)
and regexp_like(regexp_replace(callednumber,'^256','') ,'^73')
group by  to_char(calldate,'Day') ,trunc(calldate),'Onnet' order by 2

我得到的错误是:

Err] ERROR:  function date_trunc(timestamp without time zone) does not exist
LINE 4: select  to_char(calldate,'Day') as Day, date_trunc(calldate)...

我做错了什么,或者这个错误的解决方案是什么?

4

1 回答 1

20

尝试:

... date_trunc('day',calldate) ...

对于 PostgreSQLdate_trunc()函数,您必须始终将精度指定为第一个参数。

详情在这里

于 2013-01-15T15:37:18.643 回答