Updated on 2025-08-22 GMT+08:00

GQL Syntax

GQL is a standard query language designed for graph databases. For details about the GQL standard, see the GQL document released by ISO.

Supported GQL Clauses

GES supports the following GQL clauses:

Table 1 Supported GQL clauses

Keyword

Support

Example

Remarks

insert

Only supported by the database edition

insert (n:movie{_ID_:'1a', genres: 'Comedy|Drama'}) return n

-

set

Only supported by the database edition

match (n) where element_id(n)='1a' set n.movieid=1 return n

-

remove

Only supported by the database edition

match (n) where element_id(n)='1a' remove n.movieid return n

-

delete

Only supported by the database edition

match (n) where element_id(n)='1a' delete n

-

match

Partially supported

match (n where element_id(n)= '1a')-->(m) return count(*)

For details, see Pattern Matching.

optional match

Partially supported

match (n) where id(n)= '1a' optional match (n)-->(m) return count(*)

For details, see Pattern Matching.

let

Supported

let a=1, value b::long=2 return a,b

When type matching is not considered, it can be equivalently represented as the WITH semantics in Cypher.

for

Supported

for a in [1,2,3] return a

The offset/ordinality parameter is currently not supported. It can be equivalently represented as the UNWIND semantics in Cypher.

filter/where

Supported

match (n) where element_id(n)='1a' return n

-

order by

Supported

match (n:movie) return n order by n.genres asc

-

limit/offset

Supported

match (n:movie) return n skip 10 limit 10

-

union&union all

Supported

return 1 as a union return 2 as a

-

next yield

Supported

match (n:user) return n union all match (n:movie) return n next yield n as b match (b)-->(m) return m

Currently, the yield keyword must be included to declare variables used in later stages.

call

Partially supported

call db.indexes()

-

  1. Currently, multi-graph joint query and the USE GRAPH semantics are not supported.
  2. The SELECT... FROM... GROUP BY... HAVING clause is not supported.
  3. The at schema operation is not supported.
  4. Currently, only the union operation is supported for the result set. The set operation semantics such as except, intersect, and otherwise are not supported.
  5. The keyword call can only be followed by a procedure name. Subqueries of the call style are not supported.

Pattern Matching

In GQL, pattern matching generally refers to Cypher. Patterns described in the following table that do not include the match keyword are graph patterns within the match clause.

Table 2 Pattern matching

Item

Description

Example

Supported Version

Vertex pattern

Indicates a group of vertices sharing the same feature.

(n:movie{title:'hello'})

2.4.15

(n:movie where n.title='hello')

(n:movie|user)

Edge pattern

Supports edge patterns with direction, without direction, and with label/property filtering. Allows edge queries by specifying the IDs of both start and end vertices.

(n)-[r]-> (m), (n)<-[r]-(m), (n)-[r]- (m)

(n)-[r:rate{Rating:1}]-(m)

(n)-[r:rate where r.Rating=1]-(m)

Path

Supports anonymous paths.

match (n)-[r]->(m)-->(s)

Supports named paths.

match p=(n)-[r]->(m)-->(s)

Variable-length paths

match p=trail (n)-[r]->{1,3}(m) where element_id(n)='46' return p

Deduplicated variable-length traversals

match p=trail (n)-[r]->{1,3}(m) where element_id(n)='46' return distinct m

Nested paths

match (d:Stop)

((s:Stop)-[:NEXT]->(f:Stop) where s.time <> f.time){1,3}

(a:Stop)

RETURN d.departs AS departureTime, a.arrives AS arrivalTime

Not supported

Path mode

Supports walk, trail, simple, and acyclic path modes. See Path Mode for details.

match trail (n)-[r]-{1,3}(m), trail (n)--(m1) where element_id(n)='0' return count(*)

2.4.15

Other

Multiple patterns in the match clause

match (n)-[r]->(m), (m)-->(s) return count(*)

Multiple match statements

match (n)-[r]->(m) with m match (m)-->(s) return count(*)

  1. The optional keyword cannot be followed by a subquery enclosed in curly braces.
  2. The SHORTEST and GROUP keywords cannot follow the match keyword.
  3. The keep keyword is not currently supported.

Path Mode

In the match statement, you can input several graph patterns representing multiple paths, with each path separated by commas. GQL supports the following four path modes, which are configured as optional keywords before the graph pattern. If no keyword is configured, the default value walk is used.

Table 3 Path modes

Keyword

Description

walk

In the same path, both vertices and edges can be repeated.

trail

In the same path, edges cannot be duplicated.

simple

In the same path, intermediate vertices except the end vertex cannot be the same.

acyclic

In the same path, each vertex must be unique.

Supported Types

  1. The mapping between basic data types in GQL and GES types is as follows:
    Table 4 GQL basic types

    GQL Type

    GES Type

    Remarks

    bool

    Boolean

    -

    string

    string, char array, and enum

    -

    int32

    Integer

    -

    int64

    long

    -

    float

    float

    -

    double

    double

    -

    datetime

    date

    The smallest time unit supported in GES is second.

  2. Additionally, there are some complex types in GQL, with their construction methods and GES support detailed as follows:
    Table 5 GQL complex types

    GQL Type

    Support

    Example

    vertex/node

    Supported

    match (n) return n

    edge/ relationship

    Supported

    match (n)-[r]->(m) return r

    array/list

    Supported

    return [1,2,3] as li

    record

    Supported

    match (n)-->(m) return {start:id(n), end:id(m)}

    path

    Supported

    match p=(n1)-[:friends]-{1,2}(n2) return p limit 10

    1. Among the complex types mentioned in GQL complex types, only List can be used to correspond to multi-valued properties in GES. Other types cannot be assigned as values to properties on vertices or edges using the SET statement.
    2. Currently, the path type can be created using the match statement, but connecting multiple paths or constructing a path from vertices and edges is not yet supported.
    3. Display construction and assignment for graph and table objects are currently unsupported.
    4. Support for the Duration type compliant with the GQL standard is also unavailable.

Supported Expressions and Functions

  1. GQL supports the expressions and functions in Supported Expressions, Functions, and Procedures. GQL also supports the following functions.
    Table 6 Functions supported by GQL

    Function

    Corresponding Cypher Function

    Description

    Example

    collect_list

    collect

    Aggregate function, which collects results into a list.

    match (n:movie) return n.genres, collect_list(n) as movieList

    element_id

    id

    Obtains the vertex or edge ID.

    match (n) where element_id(n)= '0' return n

    character_length

    size

    Obtains the length of a string.

    return character_length('abc')

    path_length

    length

    Obtains the path length.

    match p=TRAIL (n)--{1,2}(m) where id(n)='0' return path_length(p)

  2. The following expressions are supported:
    Table 7 Expressions supported by GQL

    Expression

    Description

    Example

    ||

    Supports concatenation between lists and between strings.

    return 'abc'||'de', [1,2]||[3,4]

  3. Supports GQL-style value type predicate expressions.
    Table 8 Judgment expressions supported by GQL

    Category

    Type Keyword

    Example

    Basic type determination

    Boolean, string, int, long, float,double,

    datetime,node,edge,path,list,record

    let a=1 return a is ::int

    Nested type determination

    list

    let a=[1,2] return a is ::list<int>

    Union type

    any

    Note: any<int|string|long> indicates that a type is one of int, string, and long.

    for a in [1,2,'a1'] return a is ::any<int|string|long>

    Currently, mod and trigonometric functions are not supported.

Index Support

Currently, GQL supports vertex indexes with hasLabel set to true and supports single-value matching and multi-value matching. For details about how to create and edit indexes, refer to Index Operation APIs.

Example:

Index Type

Label

Index Attribute

Remarks

GlobalCompositeVertexIndex

true

movieid

Single-attribute index

GlobalCompositeVertexIndex

true

movieid, title

Multi-attribute index

The indexes in the above table serve as an example. The following queries can utilize the indexes:

Type

Matching Mode

Example

Single-attribute index

Exact match - single value

match (n:movie) where n.movieid = 0 return n

Exact match - multiple values

match (n:movie) where n.movieid in [0, 1, 2] return n

Range match

match (n:movie) where n.movieid > 0 return n

match (n:movie) where n.movieid >= 0 return n

match (n:movie) where n.movieid < 0 return n

match (n:movie) where n.movieid <= 0 return n

Multi-value index

Exact match

match (n:movie) where n.movieid = 0 and n.title='' return n

When performing EXPLAIN or PROFILE on a query statement that utilizes an index, the NodeIndexSeek operator is printed, indicating that the index was used for the query.