Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

discarding milliseconds from the average time calculated

Here is my code:

SELECT cluster_id, AVG(min_per_imei_cluster::TIME) as avg_time 
FROM arrival
group by cluster_id

The avg_time column gives values with milliseconds and beyond. How do I truncate or round to the nearest second?

I tried using

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

AVG(min_per_imei_cluster::TIME)::timestamp(0)

but got the following error:

SQL Error [42846]: ERROR: cannot cast type interval to timestamp without time zone

>Solution :

It looks like you can use the date_trunc function to specify the level of precision that you want. So in this instance, you would do date_trunc(‘second’,min_per_imei_cluster).

I hope this helps!

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading