Skip to content

Commit a8214df

Browse files
Add further considerations for CASE expressions (#1013)
Co-authored-by: Jens Pryce-Åklundh <[email protected]>
1 parent 5642cb1 commit a8214df

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

modules/ROOT/pages/queries/case.adoc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,3 +323,29 @@ RETURN n.name, n.colorCode
323323
|===
324324

325325
For more information about using the `SET` clause, see xref::clauses/set.adoc[SET].
326+
327+
== Further considerations
328+
329+
`CASE` result branches are statically checked prior to execution.
330+
This means that if a branch is not semantically correct, it will still throw an exception, even if that branch may never be executed during runtime.
331+
332+
In the following example, `date` is statically known to be a `STRING` value, and therefore would fail if treated as a `DATE` value.
333+
334+
.Not allowed
335+
[source, cypher, role=test-fail]
336+
----
337+
WITH "2024-08-05" AS date, "string" AS type
338+
RETURN CASE type
339+
WHEN "string" THEN datetime(date)
340+
WHEN "date" THEN datetime({year: date.year, month: date.month, day: date.day})
341+
ELSE datetime(date)
342+
END AS dateTime
343+
----
344+
345+
.Error message
346+
[source, error]
347+
----
348+
Type mismatch: expected Map, Node, Relationship, Point, Duration, Date, Time, LocalTime, LocalDateTime or DateTime but was String (line 4, column 38 (offset: 136))
349+
" WHEN 'date' THEN datetime({year: date.year, month: date.month, day: date.day})"
350+
^
351+
----

0 commit comments

Comments
 (0)