src-d/go-kallax

Handling infinity & -infinity timestampz values.

amattn opened this issue · 1 comments

According to https://www.postgresql.org/docs/10/static/datatype-datetime.html#DATATYPE-DATETIME-SPECIAL-TABLE

the special timestamp and timestampz values of infinity and -infinity are not stored as actual timestamps, but rather "specially represented inside the system and will be displayed unchanged"

lib/pq has a way of handling these with the EnableInifinityTs() function:

https://godoc.org/github.com/lib/pq#EnableInfinityTs

Currently any Postgres timestamp column will fail when scan/parsing if the value is one of the infinity fields. You will see the error if the value is infinity or -infinity:

sql: Scan error on column index 0: unsupported driver -> Scan pair: []uint8 -> *time.Time

Can we expose the ability to call this EnableInifinityTs() function somewhere to enable support for rows that use the special inf values?

It doesn't make sense to me to just call EnableInifinityTs every time because postgres is special in that -infinity is earlier then epoch, and infinity is after max time, so behavior around testing equality/before/after near zero and max values requires understanding these differences.

Hello,

Thanks for taking the time to report this issue.

If I understood correctly, pq will just take two arbitrary time.Time values and map them to -Infinity and +Infinity. I understand this is the only possible approach, as go stores time as an integer, but I don't see this as a good solution. -Inf or +Inf timestamps make little sense in the real world, at least in my opinion.

Since kallax is meant to handle their own databases and not to adapt into existing ones I see no point in adding this feature, as kallax will never generate a -Inf or +inf timestamp in the first place.