[SOLVED] How to return interval as a ISO8601 duration?


This Content is from Stack Overflow. Question asked by Frank Fiegel

Suppose I have a query:

SELECT max(ended_at) - min(started_at)
FROM test_run

How would I return the result as a ISO8601 duration?

i.e. If time different is 5 seconds, I would I expect the response to be PT5S.


Set the IntervalStyle to the desired format:

SET IntervalStyle to iso_8601; -- can be done in the config file as well

SELECT INTERVAL '5 seconds';

Result: PT5S

This Question was asked in StackOverflow by Frank Fiegel and Answered by Frank Heikens It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?