Skip to main content

Optional Clauses

Optional clauses are equivalent to left-outer joins. If a variable within an optional clause does not match with existing results, the value of that variable is simply bound to nil.

Currently, we do not support starting your where clause with an optional map. This will always return an empty result, as of 0.13.0.

{
"select": ["?person", "?name", "?age"],
"where": [
["?person", "person/age", "?age"],
{
"optional": [
["?person", "person/fullName", "?name"],
["?person", "person/favNums", "?favNums"]
]
}
]
}

Here is an example of using an optional clause. Immediately after the optional clause, we use a filter that keeps all ?nums values that are nil or ?nums that = 98.

{
"select": [{ "?person": ["favNums"] }, "?name", "?age", "?nums"],
"where": [
["?person", "person/fullName", "?name"],
{
"optional": [
["?person", "person/age", "?age"],
["?person", "person/favNums", "?nums"]
]
},
{ "filter": ["(if (nil? ?nums) true (= 98 ?nums))"] }
]
}