CaseWhenExpression

data class CaseWhenExpression<T : Any>(val operand: ScalarExpression<*>?, val whenClauses: List<Pair<ScalarExpression<*>, ScalarExpression<T>>>, val elseClause: ScalarExpression<T>?, val sqlType: SqlType<T>, val isLeafNode: Boolean = false, val extraProperties: Map<String, Any> = emptyMap()) : ScalarExpression<T> (source)

Case-when expression, represents a SQL case-when clause.

There are two kind of case-when clauses in SQL, one is simple case-when clause, which has an operand following the case keyword, for example:

case operand when a then 1 when b then 2 else 3

The other is searched case-when clause, which doesn't have an operand, for example:

case when a = 1 then 1 when b = 2 then 2 else 3

See the SQL BNF Grammar https://ronsavage.github.io/SQL/sql-2003-2.bnf.html#case%20expression

Since

3.6.0

Constructors

Link copied to clipboard
constructor(operand: ScalarExpression<*>?, whenClauses: List<Pair<ScalarExpression<*>, ScalarExpression<T>>>, elseClause: ScalarExpression<T>?, sqlType: SqlType<T>, isLeafNode: Boolean = false, extraProperties: Map<String, Any> = emptyMap())

Properties

Link copied to clipboard

the result in case no when clauses are matched.

Link copied to clipboard
open override val extraProperties: Map<String, Any>

Extra properties of this expression, maybe useful in SqlFormatter to generate some special SQLs.

Link copied to clipboard
open override val isLeafNode: Boolean = false

Check if this expression is a leaf node in expression trees.

Link copied to clipboard

the case operand, might be null for simple case-when clauses.

Link copied to clipboard
open override val sqlType: SqlType<T>

The SqlType of this column or expression.

Link copied to clipboard

pairs of when clauses and their results.

Functions

Link copied to clipboard
open override fun aliased(label: String?): ColumnDeclaringExpression<T>

Wrap this instance as a ColumnDeclaringExpression.

Link copied to clipboard

And operator, translated to the and keyword in SQL.

Link copied to clipboard

Order this column or expression in ascending order.

Link copied to clipboard
open override fun asExpression(): ScalarExpression<T>

Convert this instance to a ScalarExpression.

Link copied to clipboard

Between operator, translated to between .. and .. in SQL.

Link copied to clipboard

Cast the current column or expression to the given SqlType.

Link copied to clipboard

Order this column or expression in descending order, corresponding to the desc keyword in SQL.

Link copied to clipboard
infix operator fun <T : Number> ColumnDeclaring<T>.div(value: T): BinaryExpression<T>
infix operator fun <T : Number> ColumnDeclaring<T>.div(expr: ColumnDeclaring<T>): BinaryExpression<T>

Divide operator, translated to / in SQL.

Link copied to clipboard
infix fun <T : Any> ColumnDeclaring<T>.eq(value: T): BinaryExpression<Boolean>

Equal operator, translated to = in SQL.

Link copied to clipboard

Greater operator, translated to > in SQL.

Link copied to clipboard

Greater-eq operator, translated to >= in SQL.

Link copied to clipboard

Greater operator, translated to > in SQL.

Link copied to clipboard

Greater-eq operator, translated to >= in SQL.

Link copied to clipboard
fun <T : Any> ColumnDeclaring<T>.inList(vararg list: T): InListExpression

In-list operator, translated to the in keyword in SQL.

Link copied to clipboard

Check if the current column or expression is not null, translated to is not null in SQL.

Link copied to clipboard

Check if the current column or expression is null, translated to is null in SQL.

Link copied to clipboard

Less operator, translated to < in SQL.

Link copied to clipboard

Less-eq operator, translated to <= in SQL.

Link copied to clipboard

Like operator, translated to the like keyword in SQL.

Link copied to clipboard

Less operator, translated to < in SQL.

Link copied to clipboard

Less-eq operator, translated to <= in SQL.

Link copied to clipboard
infix operator fun <T : Number> ColumnDeclaring<T>.minus(value: T): BinaryExpression<T>
infix operator fun <T : Number> ColumnDeclaring<T>.minus(expr: ColumnDeclaring<T>): BinaryExpression<T>

Minus operator, translated to - in SQL.

Link copied to clipboard
infix fun <T : Any> ColumnDeclaring<T>.neq(value: T): BinaryExpression<Boolean>

Not-equal operator, translated to <> in SQL.

Link copied to clipboard

Negative operator, translated to the not keyword in SQL.

Link copied to clipboard

Not-between operator, translated to not between .. and .. in SQL.

Link copied to clipboard

Not-equal operator, translated to <> in SQL.

Link copied to clipboard

Not-in-list operator, translated to the not in keyword in SQL.

Link copied to clipboard

Not like operator, translated to the not like keyword in SQL.

Link copied to clipboard

Or operator, translated to the or keyword in SQL.

Link copied to clipboard
infix operator fun <T : Number> ColumnDeclaring<T>.plus(value: T): BinaryExpression<T>
infix operator fun <T : Number> ColumnDeclaring<T>.plus(expr: ColumnDeclaring<T>): BinaryExpression<T>

Plus operator, translated to + in SQL.

Link copied to clipboard
infix operator fun <T : Number> ColumnDeclaring<T>.rem(value: T): BinaryExpression<T>
infix operator fun <T : Number> ColumnDeclaring<T>.rem(expr: ColumnDeclaring<T>): BinaryExpression<T>

Mod operator, translated to % in SQL.

Link copied to clipboard
infix operator fun <T : Number> ColumnDeclaring<T>.times(value: T): BinaryExpression<T>
infix operator fun <T : Number> ColumnDeclaring<T>.times(expr: ColumnDeclaring<T>): BinaryExpression<T>

Multiply operator, translated to * in SQL.

Link copied to clipboard

Cast the current column or expression's type to Double.

Link copied to clipboard

Cast the current column or expression's type to Float.

Link copied to clipboard
@JvmName(name = "booleanToInt")
fun ColumnDeclaring<Boolean>.toInt(): CastingExpression<Int>

Cast the current column or expression's type to Int.

Link copied to clipboard

Cast the current column or expression's type to Long.

Link copied to clipboard

Cast the current column or expression's type to Short.

Link copied to clipboard

Unary minus operator, translated to - in SQL.

Link copied to clipboard

Unary plus operator, translated to + in SQL.

Link copied to clipboard
open override fun wrapArgument(argument: T?): ArgumentExpression<T>

Wrap the given argument as an ArgumentExpression using the sqlType.

Link copied to clipboard

Xor operator, translated to the xor keyword in SQL.