To use variables in your tests, you must enable substitution by adding control substitution on to the top of your .slt file.
Variable Substitution
Supports standard shell-like syntax:
$foo (short)${foo} (long)${bar:default} (with default value)
Special Variables:
$__TEST_DIR__: Path to a temporary directory specific to the current test case.$__NOW__: Current Unix timestamp in nanoseconds.$__DATABASE__: Name of the current database.
Binding results with 'let'
Use the let keyword to capture results from a query into variables for use in subsequent statements.
Requirements:
- The query must return exactly 1 row.
- The number of columns must match the number of variables.
- You must have
control substitution on enabled to use the variables later.
Example
control substitution on
let id
SELECT id FROM users WHERE name = 'alice'
query TTT
SELECT $id
----
1
control substitution on
# Execute a query that returns exactly 1 row with 1 column, bind result to 'id'
let id
SELECT id FROM users WHERE name = 'alice'
# Multiple variables can be bound from a single query
let user_id, user_name, user_email
SELECT id, name, email FROM users WHERE id = 1
# Use the bound variable in subsequent queries
query TTT
SELECT $user_id, $user_name, $user_email
----
1 alice alice@example.com