Replies: 1 comment 1 reply
-
|
The above query shows that
The query builder created in our episodes are a simplified version of the final tool that was built.
If you do that then you will just get a SQL error if the table is empty. And that may be just fine for your use case, but in certain kinds of queries it can definitely be a problem. You can also use the $0.date.max().ifnull(Date.distantPast) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to understand the logic for why max() and all the other similar operators produce an optional value. In my case for some reason, $0.date.max() is producing an optional. I can coerce it to a date with $0.date.max().ifnull(Date.distantPast), but that doesn't seem right in this simple scenario.
Error: Initializer 'init(queenID:date:count:)' requires the types 'Optional' and 'Date' be equivalent
In the definition included below, there is no non-optional overload of max.
https://www.pointfree.co/episodes/ep317-sql-builders-advanced-selects In this episode, the functions are not returning an optionally wrapped type.
/// A maximum aggregate of this expression. /// /// ```swift /// Reminder.select { $0.date.max() } /// // SELECT max("reminders"."date") FROM "reminders" /// ``` /// /// - Parameters filter: A `FILTER` clause to apply to the aggregation. /// - Returns: A maximum aggregate of this expression. public func max( filter: (some QueryExpression<Bool>)? = Bool?.none ) -> some QueryExpression<QueryValue._Optionalized.Wrapped?> { AggregateFunction("max", [queryFragment], filter: filter?.queryFragment) }If I do the minimal example of 'FetchAll(QueenLocation.select{$0.date.max()}) var data' I get the following type
I've done this for now,
date: #sql("max(\($0.date))")Beta Was this translation helpful? Give feedback.
All reactions