I have a table with an interval
column, something like this.
CREATE TABLE validity (
window INTERVAL NOT NULL
);
Assume the value stored is 'P3DT1H' which is in iso_8601
format.
When I try to read the value, it comes in regular postgres format.
3 days 01:00:00
However I want the value in iso_8601
format. How can I achieve it?
You can use
SET intervalstyle
query and set the style toiso_8601
. Then, when you output the results, they will be in ISO 8601 format.If you are looking for a way to change
intervalstyle
for all sessions on a server level, you can update it in your configuration file:Edit this file and add the following line:
In my case the file already had a commented out line with
intervalstyle
, and its value waspostgres
. You should change it and restart the service.That way you won't have to change the style from golang each time you run a query.