The following subqueries are supported in GQL query statements:
Subquery list
| Name | Summary |
|---|---|
ARRAY
subquery
|
Subquery expression that produces an array. |
EXISTS
subquery
|
Checks if a subquery produces at least one row. |
IN
subquery
|
Checks if a subquery produces a specified value. |
VALUE
subquery
|
Subquery expression that produces a scalar value. |
ARRAY
subquery
ARRAY { GRAPH graph_name gql_query_expr }
Description
Subquery expression that produces an array. If the subquery produces zero rows,
an empty array is produced. Never produces a NULL
array. This can be used
wherever a query expression is supported in a GQL query statement.
Definitions
-
graph_name: The name of the property graph. -
gql_query_expr: A GQL query expression.
Return type
ARRAY<T>
Examples
In the following query, an array of transfer amounts is produced for each Account
owned by each Person
node:
GRAPH
graph_db
.
FinGraph
MATCH
(
p
:
Person
)
-[:
Owns
]-
> (
account
:
Account
)
RETURN
p
.
name
,
account
.
id
AS
account_id
,
ARRAY
{
GRAPH
graph_db
.
FinGraph
MATCH
(
a
:
Account
)
-[
transfer
:
Transfers
]-
> (
:
Account
)
WHERE
a
=
account
RETURN
transfer
.
amount
AS
transfers
}
AS
transfers
;
/*-------------------------------+
| name | account_id | transfers |
+-------------------+-----------+
| Alex | 7 | [300,100] |
| Dana | 20 | [500,200] |
| Lee | 16 | [300] |
+-------------------------------*/
EXISTS
subquery
EXISTS { GRAPH graph_name gql_query_expr }
EXISTS { match_statement }
EXISTS { graph_pattern }
Description
Checks if the subquery produces at least one row. Returns TRUE
if
at least one row is produced, otherwise returns FALSE
. Never produces NULL
. You can't use an EXISTS
subquery in the WHERE
clause of a path pattern. Instead, use a FILTER
statement.
Definitions
-
graph_name: The name of the property graph. -
gql_query_expr: A GQL query expression. -
match_statement: A pattern matching operation to perform on a graph. For more information, seeMATCHstatement . -
graph_pattern: A pattern to match in a graph. For more information, see graph pattern definition .
Return type
BOOL
Examples
The following query checks whether any person named "Lee"
owns an
account. The subquery contains a graph query expression.
GRAPH
graph_db
.
FinGraph
RETURN
EXISTS
{
GRAPH
graph_db
.
FinGraph
MATCH
(
p
:
Person
{
Name
:
"Lee"
}
)
-[
o
:
Owns
]-
> (
a
:
Account
)
RETURN
p
.
Name
LIMIT
1
}
AS
results
;
/*---------+
| results |
+---------+
| true |
+---------*/
You can include a MATCH
statement or a graph pattern in an EXISTS
subquery. The following examples include two ways to construct the subquery
and produce similar results:
GRAPH
graph_db
.
FinGraph
RETURN
EXISTS
{
MATCH
(
p
:
Person
{
Name
:
"Lee"
}
)
-[
o
:
Owns
]-
> (
a
:
Account
)
}
AS
results
;
/*---------+
| results |
+---------+
| true |
+---------*/
GRAPH
graph_db
.
FinGraph
RETURN
EXISTS
{
(
p
:
Person
{
Name
:
"Lee"
}
)
-[
o
:
Owns
]-
> (
a
:
Account
)
}
AS
results
;
/*---------+
| results |
+---------+
| true |
+---------*/
IN
subquery
value [ NOT ] IN { GRAPH graph_name gql_query_expr }
Description
Checks if value
is present in the subquery result. Returns TRUE
if the
result contains the value
, otherwise returns FALSE
.
Definitions
-
graph_name: The name of the property graph. -
value: The value look for in the subquery result. -
IN:TRUEif the value is in the subquery result, otherwiseFALSE. -
NOT IN:FALSEif the value is in the subquery result, otherwiseTRUE. -
gql_query_expr: A GQL query expression.
Details
The subquery result must have a single column and that column type must
be comparable to the value
type. If not, an error is
returned. You can't use an IN
subquery in the WHERE
clause of a path pattern. Instead, use a FILTER
statement.
Return type
BOOL
Examples
The following query checks if 'Dana'
is a name of a person who owns an
account.
GRAPH
graph_db
.
FinGraph
RETURN
'Dana'
IN
{
GRAPH
graph_db
.
FinGraph
MATCH
(
p
:
Person
)
-[
o
:
Owns
]-
> (
a
:
Account
)
RETURN
p
.
name
}
AS
results
;
/*---------+
| results |
+---------+
| true |
+---------*/
VALUE
subquery
VALUE { GRAPH graph_name gql_query_expr }
Description
A subquery expression that produces a scalar value.
Definitions
-
graph_name: The name of the property graph. -
gql_query_expr: A GQL query expression.
Details
The result of the subquery must have a single column. If the subquery returns
more than one column, the query fails with an analysis error. The result type of
the subquery expression is the produced column type. If the subquery produces
exactly one row, that single value is the subquery expression result. If the
subquery returns zero rows, the subquery expression result is NULL
. If the
subquery returns more than one row, the query fails with a runtime error.
Return type
The same as the column type in the subquery result.
Examples
The following query returns the name of any person whose country
property
is "Australia"
:
GRAPH
graph_db
.
FinGraph
RETURN
VALUE
{
GRAPH
graph_db
.
FinGraph
MATCH
(
p
:
Person
{
country
:
"Australia"
}
)
RETURN
p
.
name
LIMIT
1
}
AS
results
;
/*---------+
| results |
+---------+
| Alex |
+---------*/

