Run-Time Context

Session and Query Contexts in the SQL Standard

The SQL standard says that each session has a session context, which contains some attributes of the session that are exposed by the SQL language. These attributes are set when the session starts. They include the timezone, the locale; the current time (in several forms); the user (in several aspects); the default schema; and the default SQL path.

Some attributes (like the timezone) can be changed by the user in SQL; others (like the current time) are set by the s-Server, and the user can read the value in SQL. The latter group behave like functions, and the former group behave like variables.

Each statement (ie query or DML statement) has its own run-time context, which contains the attributes pertinent to execution, copied from the session context In standard SQL the run-time context is constant: the user can’t change the attributes, and they don’t change by themselves. Even if query execution takes a long time, its time attributes stay constant.

The run-time attributes include the locale and the timezone, not available from SQL; as well as the attributes in the following table, which are exposed in SQL:

Attribute Description
LOCALTIME the time of day, without timezone
LOCALTIMESTAMP the date & time, without timezone
SYSTEM_USER operating-system user id
SESSION_USER database user id

(Syntactically, these all look like identifiers, but they behave as functions with no argument.)

Session and Query Contexts in the SQLstream s-Server

The current version of the s-Server supports a simplified version of these attributes. Roles and privileges are not yet supported. The s-Server does not yet distinguish individual users, so SESSION_USER is simply “sa”, (the database administrator). SYSTEM_USER is the unix user that started the s-Server.


The session locale and timezone are inherited from the s-Server. The s-Server locale is set from the unix environment variable LOCALE when the s-Server is started, and the s-Servertimezone is always UTC. All rowtimes are in the s-Server’s timezone. It’s simplest if all JDBC clients run in the same timezone as the s-Server. By default this is UTC.

Following the SQL standard, the time-valued attributes are constant, and return the moment the query was prepared. However a streaming query can run for a very long time, so as a practical necessity we have added the attribute CURRENT_ROW_TIMESTAMP, which changes for each row, being set to the approximate system time of the s-Server.

The analogous CURRENT_ROW_DATE and CURRENT_ROW_TIME do not exist; these values can be extracted from CURRENT_ROW_TIMESTAMP.

CURRENT_ROW_TIMESTAMP should not be confused with ROWTIME. ROWTIME is an operator which is applied to a row in a stream to get its rowtime (a timestamp). ROWTIME behaves like a pre-defined column name that occurs in all streams. CURRENT_ROW_TIMESTAMP is an operator that applies to a query result and returns the latest rowtime seen in the results. (Since the result of a query is essentially a stream, usually an anonymous stream, CURRENT_ROW_TIMESTAMP returns the stream clock. For more information, see the topic What are Rowtime Bounds? in the Concepts Guide.