graphile / crystal

🔮 Graphile's Crystal Monorepo; home to Grafast, PostGraphile, pg-introspection, pg-sql2 and much more!
https://graphile.org/
Other
12.61k stars 571 forks source link

Interval column not working if intervalstyle is set to non default. #1438

Closed xvaara closed 3 years ago

xvaara commented 3 years ago

Summary

Interval datatype doesn't work if intervalstyle = 'iso_8601', it returns 0 on every time element.

Possible Solution

so maybe issue a SET intervalstyle = 'postgres'; on connection open if there are interval types in the schema? for fix the code to recognise at least the iso_8601 style. or note somewhere to run:
ALTER DATABASE test SET intervalstyle = 'postgres'; or change postgresql.conf if it's global.

benjie commented 3 years ago

Another solution would be to parse the ISO8601 interval syntax if we can easily differentiate it. I believe I reimplemented the interval parser for performance reasons, so this should be feasible.

xvaara commented 3 years ago

It seems that ISO8601 duration always starts with P, so that might be easy to check. I don't think it's possible for postgres interval/duration to start with a P.

benjie commented 3 years ago

I've decided to raise this as a documentation issue rather than a bug in PostGraphile. It'd be a lot of effort to support all the different styles of various datatypes that PostgreSQL supports, and since the workaround is easy (tell pgSettings to set it back to the default value), I don't think it's worth spending time there.

Documentation updated here: https://github.com/graphile/graphile.github.io/commit/2005eae757daaad66350e3df4e78412ea368c6a1

bbigras commented 3 years ago

It seems that ISO8601 duration always starts with P, so that might be easy to check. I don't think it's possible for postgres interval/duration to start with a P.

Doesn't it start with a P with intervalstyle = 'iso_8601'?