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
.
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
.
3
Answers
For my particular use case, I was able to do it as:
Set the IntervalStyle to the desired format:
Result: PT5S
What you are looking is basically just a format conversion with specific output format. You can achieve this, in a single trip to the server by creating function which sets the
InstervalStyle
the echos back the input value. (see demo)Caution: If working strictly with dates be sure to cast them to
timestamp
– at least one of them.