erleans / pgo

Erlang Postgres client and connection pool
Apache License 2.0
80 stars 16 forks source link

Error decoding Interval #35

Closed benbro closed 4 years ago

benbro commented 4 years ago
pgo:query(<<"SELECT '7 days'::interval;">>).
** exception error: no function clause matching pg_time:decode_time(<<0,0,0,0,0,0,0,0,0,0,0,7,0,0,0,0>>) 
tsloughter commented 4 years ago

Interesting, thanks. Wonder if there is something we aren't doing for the interval type. Also, technically this issue would go on https://github.com/tsloughter/pg_types but this is fine.

tsloughter commented 4 years ago

Getting tot his one now too and mostly have a fix. Just not sure what format to return the result in.

The issue starts with I had only a test for encoding intervals and not decoding. The one that was supposed to be decoding was really just decoding timestamps.

But how best to represent a 7 day interval in Erlang?

tsloughter commented 4 years ago

Derp, nevermind, the encode makes it clear. So the result would be:

{interval, {0, 7, 0}}

Sound good?

benbro commented 4 years ago

Just {0, 7, 0} without 'interval' is better. Less verbose. Will it be possible to encoding it?

tsloughter commented 4 years ago

Hm, I ended up with {interval, {{0,0,0}, 7, 0}}.. The reason is that the first part decodes to the hours, minutes, seconds.

I suppose I can get rid of the interval atom, tho I often really think we should be using records or maps for these data types.

tsloughter commented 4 years ago

master is now updated to support this but with the format {interval, {{0,0,0}, 7, 0}} for now.

benbro commented 4 years ago

Thanks