Closed parthshah31 closed 3 years ago
I feel like you can do this using the Experimental syntax:
select $ distinct $ do
dd <- from $ generateSeries begin end interval
orderBy $ dateTrunc "hour" dd
pure $ dateTrunc "hour" dd
generateSeries :: SqlExpr (Value UTCTime) -> SqlExpr (Value UTCTime) -> SqlExpr (Value Interval) -> SqlQuery (Value UTCTime)
generateSeries begin end interval =
pure $ unsafeSqlFunction "generate_series" begin end interval
But I may be wrong here - please let me know how this works for you!
Awesome will try that out! Re: Interval
type did this https://github.com/bitemyapp/esqueleto/issues/263 ever get resolved? Or should I just use an unsafeSqlValue there? I figure a (SqlString a) => .... -> SqlExpr (Value a) -> ...
will not work since it needs the :: interval
when you write the query in SQL
This worked! Added implementation to extensions library here for component use: https://github.com/polimorphic/esqueleto-extensions/blob/main/src/Database/Esqueleto/Datetime.hs
Looking to write the following SQL query in esqueleto:
Curious how to do the
generate_series
in a composable way. Most the unsafeSql examples only have a singleSELECT
statement. Here the complexity is on theFROM
side. Ideas?I have a
date_trunc
function I've written as part of a larger extensions library: https://github.com/polimorphic/esqueleto-extensions/blob/main/src/Database/Esqueleto/Datetime.hs.