Forum OpenACS Q&A: Re: learn to debug an error

Collapse
Posted by Yves Goldberg on
I made a grep in package to find occurance of date_part. I found one in acs-tcl/tcl/community-core-procs-postgresql.xql

trunc(date_part('epoch',age(password_changed_date))/(60*60*24))

so maybe the right way to patch my bug is:

change in packages/robot-detection/tcl/robot-detection-procs-postgresql.xql:

===============================================
select trunc(current_timestamp - max(coalesce(modified_date, insertion_date))) from robots
===============================================
to use
===============================================
select trunc(date_part('days',current_timestamp - max(coalesce(modified_date, insertion_date))))
===============================================

Does anyone is willing to give me a feedback on this?

TIA

Collapse
Posted by Jarkko Laine on
Yves,

No, you don't need to and shouldn't use trunc anymore. So your previous solution should've been correct. So use only

date_part('days',current_timestamp - max(coalesce(modified_date, insertion_date)))

or EXTRACT which is the SQL standard (I'm not sure if it works already in 7.3, but in 7.4 sure). Please read http://www.postgresql.org/docs/7.4/interactive/functions-datetime.html for information on how these functions should be used.