Internal parameters

Variables can be defined using the .set and .setex commands. Variables are then automatically looked for when executing SQL statements for which a variable is required; they are not typed and are converted to the correct type when needed. Note that variables are shared by all the opened connections.

When setting values, the textual representation must respect the following format:

Use the .set <variablename> <variable value> command to define a variable, and the .set command to list all defined variables. The following example illustrates variables usage:

SalesTest> select * from customers where id = ##theid::int;
ERROR: No internal parameter named 'theid' required by query
SalesTest> .set theid 3
SalesTest> select * from customers where id = ##theid::int;
id | name       | default_served_by | country | city
---+------------+-------------------+---------+-----
 3 | Lew Bonito |                 1 | FR      | TLS 
(1 row)
SalesTest> .set theid 5
SalesTest> select * from customers where id = ##theid::int;
id | name | default_served_by | country | city
---+------+-------------------+---------+-----
(0 rows)
SalesTest> .set
List of defined parameters
Name  | Value
------+------
theid | 5    
(1 row)
SalesTest>
    

The .setex command also sets an internal parameter, it has two usages:

The .export command exports to a file the contents of an internal variable or the the contents of a table's value: