circuithub / rel8

Hey! Hey! Can u rel8?
https://rel8.readthedocs.io
Other
154 stars 39 forks source link

How can EXTRACT be used with this library? #236

Open guaraqe opened 1 year ago

guaraqe commented 1 year ago

The EXTRACT function has a weird syntax, for example:

EXTRACT(EPOCH FROM now())

I tried using function to write it, but it ends up with CASTs in places that create syntax errors, namely around EPOCH FROM:

CAST(EXTRACT(CAST(EPOCH FROM(CAST(now() AS timestamptz))))))

Is there any way to use a DBType that has no casts around it, or some other technique to make it work? The syntax is similar to CAST, but I see no definition of it in the library. I cannot see neither how to use unsafeLiteral to write it.

guaraqe commented 1 year ago

The problem is the casting around each one of the parameters. If there was a way to avoid it, it would be possible to apply the strategy here: https://github.com/tomjaguarpaw/haskell-opaleye/issues/291

If there is interest, I can add a function that does it, maybe just for EXTRACT.