Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Exists

The exists operator is Boolean-valued function that tests whether a subquery has a non-empty result and has the form

exists ( <query> )

where <query> is any query.

It is a syntactic shortcut for

len([<query>]) != 0

Examples


Simple example showing true for non-empty result

# spq
values exists (values 1,2,3)
# input

# expected output
true

EXISTS is typically used with correlated subqueries but they are not yet supported

# spq
let Orders = (values {product:"widget",customer_id:1})
SELECT 'there are orders in the system' as s
WHERE EXISTS (
    SELECT 1
    FROM Orders
)
# input

# expected output
{s:"there are orders in the system"}