All Products
Search
Document Center

Lindorm:Session variables

Last Updated:Dec 16, 2024

Lindorm SQL allows you to specify session variables for each session to manage the session status. The status change takes effect only for the current session and does not affect other sessions.

Applicable engines and versions

The syntax is applicable to all versions of LindormTable and LindormTSDB.

Important

The version of Lindorm SQL must be 2.8.4.0 or later. For more information about how to view the version of Lindorm SQL, see SQL versions.

Syntax

Specify session variables

set_variable_statement  ::= SET [SESSION] variable_identifier '=' literal

Query session variables

query_variable_statement ::= SELECT @@variable_identifier

Usage notes

Variable identifiers

The lexical rules for variable names are the same as the lexical rules for common identifiers. A variable name is an identifier that is used to represent a variable. For more information about identifiers, see Lexical structure of Lindorm SQL.

Session-level parameters

Important
  • The session-level parameters specified by the SET statement take precedence over the global system parameters specified by the ALTER SYSTEM statement. If a session-level parameter and a global parameter are in conflict, the session-level parameter value specified by the SET statement prevails.

  • Modifying session-level parameters can affect the behavior of the SQL engine during the session. We recommend that you fully understand the parameters before you modify the parameters. The following table describes the parameters.

Parameter

Data type

Applicable engine

Description

TIME_ZONE

Important

You can specify this parameter only for the MySQL protocol. For more information, see Use the MySQL protocol to develop applications (recommended).

String

LindormTable

Specifies the time zone of the current session. By default, the time zone is set to UTC+8.

SQL_MODE

Important

The version of Lindorm SQL must be 2.8.4.8 or later.

String

  • LindormTable

  • LindormTSDB

Specifies the parsing modes of the SQL engine. If you specify multiple parsing modes, separate the parsing modes with a comma (,).

You can set this parameter only to NO_BACKSLASH_ESCAPES, which specifies that backslashes (\) are not used as escape characters when you parse string constants.

Examples

Change the time zone of the current session

  1. Before you modify the time zone, execute the following statement to view the time zone of the current session:

    SELECT @@TIME_ZONE;

    Sample result:

    +-------------+
    | @@TIME_ZONE |
    +-------------+
    | +08:00      |
    +-------------+
  2. Change the time zone of the current session to UTC.

    SET TIME_ZONE='UTC';

    Execute the SELECT @@TIME_ZONE; statement to check whether the change takes effect. Sample result:

    +-------------+
    | @@TIME_ZONE |
    +-------------+
    | UTC         |
    +-------------+
    Note

    For more information about the relationship between the session time zone and the timestamp data, see Specify a time zone for a LindormTable connection

Specify the parsing modes of the SQL engine

  1. Query a string constant expression.

    SELECT '{\"key\":\"va\\lu\'e\r\n\"}';

    Sample result:

    +---------------------+
    | EXPR$0              |
    +---------------------+
    | {"key":"va\lu'e
    "} |
    +---------------------+
  2. Specify the parsing modes of the SQL engine. When you parse string constants, do not use backslashes (\) as escape characters.

    SET SQL_MODE='NO_BACKSLASH_ESCAPES';

    Execute the SELECT '{\"key\":\"va\\lu\'e\r\n\"}'; statement to check whether the change takes effect. Sample result:

    +-----------------------------+
    | EXPR$0                      |
    +-----------------------------+
    | {\"key\":\"va\\lu\'e\r\n\"} |
    +-----------------------------+