SESSION SET command¶
The SESSION SET command sets the schema, graph, temporary graph, or parameters for the current session.
To view details about the current session, use SHOW CURRENT_SESSION.
Syntax¶
- session_set_command
session_set_command ::=
'SESSION' 'SET' (
'SCHEMA' schema_reference
| 'GRAPH' ((schema_reference '/')? graph_name | temp_graph_name)
| 'VALUE' (parameter_name '=' value_expression) (',' (parameter_name '=' value_expression) )*
)
Parameters¶
schema_reference¶
The reference to the path of the schema.
- When setting the schema for the current session, it specifies the path of the schema to be set for the current session. If not set, the schema in the current session defaults to
/default_schema. - When setting the graph for the current session, it specifies the schema path of the graph to be set for the current session. To set a graph that resides outside the schema in the current session as the graph for the current session, the schema path must be specified.
The path is case-sensitive and must match the path of an existing schema. Both absolute and relative schema paths can be used in the command. You can use CREATE SCHEMA to create a schema. For information about viewing the schema for the current session, see SHOW CURRENT_SCHEMA.
Note
To set a schema or graph for the current session, the current user must have access to the target schema or the graph's parent schema, either implicitly or through an explicit USAGE grant. Every user has implicit access to /default_schema. This requirement does not apply to temporary graphs. For more information, see Schema access control.
graph_name¶
The name of the graph to be set for the current session. The graph acts as the working graph if no USE clause is specified in DQL statements. For information about creating and viewing graphs, see CREATE GRAPH and SHOW GRAPHS.
- If no graph is set for the current session, but a home graph is set for the current user, the graph in the current session is the specified home graph. In this case, the specified home graph acts as the working graph if no USE clause is specified in queries.
- If no graph is set for the current session, and no home graph is set for the current user, the graph in the current session is empty. In this case, you must use the USE clause to specify a working graph for each query.
temp_graph_name¶
The name of the temporary graph to be set for the current session. It must start with a number sign (#). The temporary graph acts as the working graph if no USE clause is specified in DQL statements. For information about creating and viewing temporary graphs, see CREATE TEMPORARY GRAPH and SHOW GRAPHS.
- If no temporary graph is set for the current session, but a home graph is set for the current user, the graph in the current session is the specified home graph. In this case, the specified home graph acts as the working graph if no USE clause is specified in queries.
- If no temporary graph is set for the current session, and no home graph is set for the current user, the graph in the current session is empty. In this case, you must use the USE clause to specify a working graph for each query.
parameter_name¶
The name of the parameter to be set for the queries in the current session. parameter_name must be an identifier that is prefixed with a dollar sign ($). For more information about identifiers, see Rules for naming identifiers.
For more information about parameters, see Configure parameters.
value_expression¶
The value of the parameter to be set in the current session. value_expression must be an expression that does not depend on any variables.
Examples¶
The following examples are based on the example dataset.
Set the schema¶
'''
// Create a schema
CREATE SCHEMA IF NOT EXISTS /my_schema
'''
'''
// Set the schema for the current session
SESSION SET SCHEMA /my_schema
'''
Set the graph in the current schema as the graph for the current session¶
'''
// Create a graph type
CREATE GRAPH TYPE IF NOT EXISTS my_graph_type AS {}
'''
'''
// Create a graph
CREATE GRAPH IF NOT EXISTS my_graph TYPED my_graph_type
'''
'''
// Set the graph for the current session
SESSION SET GRAPH my_graph
'''
Set the graph in the specified schema as the graph for the current session¶
'''
// Create a graph type
CREATE GRAPH TYPE IF NOT EXISTS my_graph_type AS {}
'''
'''
// Create a graph
CREATE GRAPH IF NOT EXISTS my_graph TYPED my_graph_type
'''
'''
// Create a schema
CREATE SCHEMA IF NOT EXISTS /my_schema
'''
'''
// Set the schema for the current session
SESSION SET SCHEMA /my_schema
'''
'''
// Set the graph for the current session
SESSION SET GRAPH /default_schema/my_graph
'''
Set the temporary graph¶
'''
// Create a temporary graph based on an existing graph
CREATE TEMPORARY GRAPH IF NOT EXISTS #movie_temporary_graph AS COPY OF movie
'''
'''
// Set the temporary graph for the current session
SESSION SET GRAPH #movie_temporary_graph
'''
Set parameters¶
SESSION SET VALUE $i_1 = 10, $i_2 = 20
The parameter $i_1 and $i_2 are set to 10 and 20, respectively in the current session. You can then use the parameters in the queries in the current session. For how to use the parameter, see Use session parameters.