Hello! I have trouble understanding the coalesce t...
# exposed
m
Hello! I have trouble understanding the coalesce type parameter
Copy code
class Coalesce<out T, S : T?>(
    private val expr: ExpressionWithColumnType<S>,
    private val alternate: Expression<out T>,
    private vararg val others: Expression<out T>
) : Function<S>(expr.columnType)
Shouldn’t it be Function<T>, since T is non-nullable and the point of coalesce is to convert a nullable expression to a non-nullable expression?
s
I dont think SQL has a restriction that it must produce a not null value
So how can Exposed?
However, the Coalesce could be reworked (afaik) to return the type of the last expression which then could be either nullable or not null and thus give the Coalesce instance a not null type parameter
m
That is true, but if I understand correctly,
T
can be nullable, but
S
is always nullable, and thus the result from
Coalesce
is always nullable even if I know it not to be. In my example, I have implemented concat operator which I want to accept only non-nullable columns/expressions:
Copy code
(name concatSpaced description concatSpaced author concatSpaced coalesce(publisher, stringLiteral("")).toTsVector()
Here, publisher is nullable, but this would not compile because
Coalesce
is
Function<S>
not
Function<T>
, so I have to cast it to
Expression<String>
manually
c
Hi @maxmello You're correct and this change was not intended behavior. A fix for this issue is underway. Please track EXPOSED-389 if you're interested.
🙏 1