Question

I have a table where exists an interval type column Duration. Currently the values are expressed as HH:MM:SS with data like:

15:32:00
17:01:00
16:02:00
... 

The problem is that in reality the data resembles only minutes and seconds and the column's values should be updated so that values will become:

15:32:00 -> 00:15:32
17:01:00 -> 00:17:01
16:02:00 -> 00:16:02

...

What kind of query should be run against the column?

Was it helpful?

Solution

SELECT EXTRACT(hour FROM duration) * INTERVAL '1' minute + EXTRACT(minute FROM duration) * INTERVAL '1' second
FROM tbl
;

EDIT

This was my original answer, which does not answer the original question:

You can try something like this:

SELECT duration - EXTRACT(hour FROM duration) * INTERVAL '1' hour
FROM tbl
;

Which extracts the hour part from the interval and subtracts that from the original value. Rewrite as UPDATE if you really need to update your data.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top