Skip to content
Developer Edition runs on one host and does not require a product license file. Need multi-host deployment or performance testing at scale? Explore Enterprise Edition

Statement block

A statement block in GQL is a collection of one or more statements that are executed sequentially.

It allows you to execute multiple independent statements as a single unit in the current working graph. The statements that make up the statement block must be separated by the keyword NEXT, which serves as the delimiter.

The syntax below describes statement blocks in NebulaGraph Database Developer Edition GQL. Most examples use queries and DML operations on persistent graphs.

Syntax

statement_block
linear_catalog_modifying_statement linear_data_modifying_statement composite_query_statement NEXT match_compute_statement control_flow_statement variable_manipulation_statement import_statement export_statement logging_statement

statement_block ::=
   ( ( linear_catalog_modifying_statement | linear_data_modifying_statement | composite_query_statement ) ( 'NEXT' ( linear_catalog_modifying_statement | linear_data_modifying_statement | composite_query_statement ) )* 
   | match_compute_statement
   | control_flow_statement 
   | variable_manipulation_statement 
   | import_statement
   | export_statement 
   | logging_statement )

Parameters

linear_catalog_modifying_statement

Data definition statements that modify the catalog. For more information, see Data definitions overview.

A statement block can contain up to one data definition statement, and this statement must be the only statement in the statement block.

linear_data_modifying_statement

Data manipulation statements that modify data. For more information, see Data manipulations overview.

A statement block can contain up to one data manipulation statement, and this statement must be the last statement in the statement block.

composite_query_statement

Composite query statements. For more information, see Composite query statement.

match_compute_statement

Match compute statements that perform iterative computations on temporary graphs. For more information, see Match compute.

control_flow_statement

Control flow statements that control the execution flow. For more information, see Control flow.

variable_manipulation_statement

Variable manipulation statements that manipulate variables. For more information, see Variable manipulation.

import_statement

Import statements that import data into temporary graphs. For more information, see IMPORT.

export_statement

Export statements that export query results to tables or files. For more information, see EXPORT.

logging_statement

Logging statements that print log messages during procedure execution. For more information, see Logging.

Examples

The following examples are based on persistent graphs and apply to the NebulaGraph Database Developer Edition runtime.

Statement block with data queries and modifications

'''
USE movie 
    MATCH (a@Actor{id:2}) 
    RETURN a 
NEXT 
USE movie 
    INSERT (a)-[r@Act{}]->(b@Movie{id:2})
'''

The preceding statement block contains two statements:

  • The first statement is a query to find the actor with ID 2.
  • The second statement is a data modification to create a movie with ID 2 and establish a relationship between the actor with ID 2 and the movie with ID 2.
'''
USE movie 
    MATCH (a@Movie{id:2}) 
    RETURN a 
NEXT 
USE movie 
    DETACH DELETE a 
'''

The preceding statement block contains two statements:

  • The first statement is a query to find the movie with ID 2.
  • The second statement is a data modification to delete the movie with ID 2 and its associated edges.

Statement block with multiple composite query statements

'''
USE movie 
    MATCH 
        (actor@Actor)-[:Act]-(movie@Movie), 
        (director@Director)-[:Direct]->(movie), 
        (audience@`User`)-[:Watch]->(movie) 
    RETURN DISTINCT audience, movie 
    LIMIT 10 
NEXT  
USE movie 
    LET valid=1, inValid=0 
    RETURN sum(valid) AS audienceCount, sum(inValid) AS inValidAudienceCount, movie GROUP BY movie 
NEXT 
USE movie 
    FILTER WHERE audienceCount>0 AND inValidAudienceCount=0 
    ORDER BY audienceCount DESC, movie.name ASC 
    RETURN movie.name AS movieName, audienceCount 
'''

The preceding statement block contains three composite query statements:

  • The first statement is a composite query to find the relationships between actors, directors, and audience members with movies, and returns information about 10 audience members and movies.
  • The second statement is a composite query to calculate the number of audience members and invalid audience members for each movie.
  • The third statement is a composite query to filter out movies with an audience count greater than 0 and an invalid audience count of 0, and sorts the results by audience count in descending order and movie name in ascending order.

Return:

+------------------+---------------+
| movieName        | audienceCount |
+------------------+---------------+
| Saw III          | 7             |
| Bread and Tulips | 3             |
+------------------+---------------+