pgo icon indicating copy to clipboard operation
pgo copied to clipboard

Support interval types

Open isaacharrisholt opened this issue 4 months ago • 5 comments

Hello! It doesn't seem like pog currently supports Postgres' interval type. There are workarounds for the time being, but it would be great to have this natively translate to a gleam/time/duration.Duration!

isaacharrisholt avatar Aug 17 '25 16:08 isaacharrisholt

Oh yes, that would be lovely!

lpil avatar Aug 17 '25 16:08 lpil

I was having a look at this and to me it seems like interval cannot be turned into a Duration. Quoting from the Duration's docs:

This type does not represent calendar periods such as “1 month” or “2 days”. Those periods will be different lengths of time depending on which month or day they apply to. For example, January is longer than February. A different type should be used for calendar periods.

But if you have a look at a Postgres interval that's exactly what we refer to as a calendar period:

Internally, interval values are stored as three integral fields: months, days, and microseconds. These fields are kept separate because the number of days in a month varies, while a day can have 23 or 25 hours if a daylight savings time transition is involved.

So in order for Pog to support this we'd need to think of how that is represented in Gleam with something different from a Duration

giacomocavalieri avatar Oct 20 '25 11:10 giacomocavalieri

Ah! That's very interesting.

How does the interval type get represented in pgo?

lpil avatar Oct 20 '25 13:10 lpil

This is its typespec, seems to be different from Postgres actual representation:

{interval, {int, int, int}, int, int}
%           ^-- {hours, minutes, seconds}
%                            ^-- days, months

giacomocavalieri avatar Oct 20 '25 13:10 giacomocavalieri

Sounds like we should open an issue with pgo to get it to return data faithful to the pg representation

lpil avatar Oct 20 '25 13:10 lpil