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
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
CodePudding user response:
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).