Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ERROR: function date_trunc(timestamp without time zone) does not exist

I have this problem. I have an sql query am trying to make to my postgres db. These queries work fine in oracle but am in the process of converting it to a postgres query but it complains. This is the query:

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

And the error am getting is this:

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

What am I doing wrong, or what is the solution to this error?

like image 822
roykasa Avatar asked Jan 15 '13 15:01

roykasa


1 Answers

Try:

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

For PostgreSQL date_trunc() function you must always specify precision as the first argument.

Details here.

like image 163
Ihor Romanchenko Avatar answered Oct 13 '22 21:10

Ihor Romanchenko