Source: https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/fe/predicates/exists/ Documentation version: v5.3.2 # EXISTS predicate The EXISTS predicate checks if a graph pattern exists or a query returns a non-empty result. ## Syntax diagramsource exists_predicate ```` exists_predicate ::= EXISTS ( '{' graph_pattern '}' | '(' graph_pattern ')' | '{' match_statement+ '}' | '{' procedure_body '}' ) ```` ## Parameters ### `graph_pattern` The graph pattern to be checked. For more information, see [Patterns](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/patterns/). ### `match_statement` The match statement that specifies the query to be checked. For more information, see [MATCH](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/dql/match/). ### `procedure_body` The processing logic of the procedure to be checked. It can consist of [primitive value variable definitions](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/variable-definition/value-variable/) and statements of the following types: - [Data query statements](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/dql/) - [Control flow statements](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/control-flow/) - [Variable manipulation statements](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/set/) - [Logging statements](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/log/) ## Examples The following examples are based on the [example dataset](https://dev-docs.nebula-graph.io/v5.3.2/database-gql-reference/overview/example-dataset/). ### Check if a node pattern exists ```` ''' USE movie RETURN EXISTS { (v WHERE v.id= 123 ) } AS a ''' ```` Return: ```` +------+ | a | +------+ | true | +------+ ```` ### Check if an edge pattern exists ```` ''' USE movie RETURN EXISTS ( ()-[e]->() WHERE e.id= 13423 ) AS b ''' ```` Return: ```` Error: [NS230]: property `id` not found in EDGE... ```` ### Check if a query returns a non-empty result ```` ''' USE movie RETURN EXISTS { MATCH (a@`User`)-[e:Watch]->(b) WHERE a.id = 123 RETURN e } AS c ''' ```` Return: ```` +------+ | c | +------+ | true | +------+ ```` ### Check if a procedure returns a non-empty result ```` ''' USE movie MATCH (a@Actor) WHERE a.id IN [1, 2, 3, 4, 5] LET d = EXISTS { VALUE born_before_1950::BOOL IF a.birthDate < DATE "1950-01-01" THEN { SET born_before_1950 = true LOG_INFO(a.name, " was born before 1950: ", born_before_1950) FILTER born_before_1950 RETURN born_before_1950 } ELSE { SET born_before_1950 = false LOG_INFO(a.name, " was born before 1950: ", born_before_1950) FILTER born_before_1950 RETURN born_before_1950 } } RETURN a.name AS actor_name, d AS born_before_1950 ''' ```` The preceding example checks if each actor with IDs 1 to 5 was born before 1950 and logs the result. The `EXISTS` predicate returns `true` if the procedure returns a non-empty result for each actor. Return: ```` +---------------+------------------+ | actor_name | born_before_1950 | +---------------+------------------+ | Mark Hamill | false | | Carrie Fisher | false | | Peter Cushing | true | | Harrison Ford | true | +---------------+------------------+ Log: 2026-01-20T07:44:00.840764 INFO - Carrie Fisher was born before 1950: false 2026-01-20T07:44:00.840794 INFO - Mark Hamill was born before 1950: false 2026-01-20T07:44:00.840804 INFO - Peter Cushing was born before 1950: true 2026-01-20T07:44:00.841090 INFO - Harrison Ford was born before 1950: true ````