Skip to content

SQL 92 Case Expression Support#27

Open
codesplode wants to merge 4 commits intoorangy:masterfrom
codesplode:pr-feature-case-expression
Open

SQL 92 Case Expression Support#27
codesplode wants to merge 4 commits intoorangy:masterfrom
codesplode:pr-feature-case-expression

Conversation

@codesplode
Copy link
Contributor

@codesplode codesplode commented May 20, 2019

Description

Adds common support for the SQL 92 case expression. Expressions of both common formats are supported.

Supported SQL

CASE With Primary Operand / Condition

SQL:

CASE (yesOrNo)
WHEN ('yes') THEN 1
ELSE 0
END

CASE Without Primary Operand / Condition

CASE
WHEN (yesOrNo = 'yes') THEN 1
WHEN (yesOrNo = 'no') THEN 0
ELSE -1
END

Kotlin Example

Taken from unit tests.

/*
 * Note the use of the word "Clause" to avoid reserved words.
 */
select(
	case<String>(literal(5)) {
		whenClause(literal(6)).thenClause(literal("false"))
		whenClause(literal(5)).thenClause(literal("true"))
		whenClause(literal(4)).thenClause(literal("false"))
		elseClause(literal("false"))
	}
)

Testing

A basic test case was added for this functionality, but could be improved to include more varying conditions, though this may not be necessary because it is ultimately using Expression<*>s for most functionality related to the conditions and values.

Edited to include a kotlin example from unit tests

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant