roykasa
roykasa

Reputation: 3027

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?

Upvotes: 16

Views: 51270

Answers (1)

Ihor Romanchenko
Ihor Romanchenko

Reputation: 28511

Try:

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

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

Details here.

Upvotes: 24

Related Questions