Contact us

SET Statement

The SET statement can be used to assign a value to either a custom or a system variable.

The syntax of the SET statement is:

SET [VAR | VARIABLE] variable_name [= | TO] CONST_EXPRESSION;

The name of the variable can be compounded with individual parts delimited by the . symbol (dot), e.g. my.var.a. The expression on the right-hand side of the assignment must always evaluate to a single scalar constant. It cannot contain a subquery, or a non-deterministic function such as RANDOM.

The currently available variables which can be set using this statement are:

Name Meaning
session.timezone The default timezone to use with all temporal functions, unless another is explicitly specified

An example of setting the session.timezone system variable:

SET session.timezone = 'America/Los_Angeles';
SELECT HOUR(1637740000::unixepoch);

--> 23

The new value set for a session variable takes effect for all statements following the SET statement until the end of current SQL input, or until another SET statement modifies the same variable.


Inspecting variable value

A value of a system/session variable can be inspected using the built-in VAR function:

SET session.timezone = 'America/Los_Angeles';
SELECT VAR('session.timezone');

--> 'America/Los_Angeles'
SET custom_var TO 123;
SELECT VAR('custom_var');

--> 123