Saved Queries
Dolt is a database designed for sharing. Dolt ships with a feature called "Saved Queries". Saved queries are queries that are created and versioned along with the database itself. You can use saved queries to make your Dolt database easier to use by adding examples of how the data in the database could be queried.
To create a saved query, you can use the Dolt CLI to save a SQL query for future use by yourself or others. You can also execute saved queries by name in using the command line.
1
us-businesses $ dolt sql --save "Example saved query" -q "show tables"
2
+----------------+
3
| Table |
4
+----------------+
5
| business_types |
6
| businesses |
7
| naics |
8
| sic |
9
+----------------+
10
us-businesses $ dolt sql -x "Example saved query"
11
Executing saved query 'Example saved query':
12
show tables
13
+----------------+
14
| Table |
15
+----------------+
16
| business_types |
17
| businesses |
18
| naics |
19
| sic |
20
+----------------+
Copied!
This query is written to a special Dolt system table dolt_query_catalog. You can add, modify, or delete saved queries by changing that system table.
1
us-businesses $ dolt sql -q "select * from dolt_query_catalog"
2
+---------------------+---------------+---------------------+-------------+-------------+
3
| id | display_order | name | query | description |
4
+---------------------+---------------+---------------------+-------------+-------------+
5
| Example saved query | 1 | Example saved query | show tables | |
6
+---------------------+---------------+---------------------+-------------+-------------+
7
us-businesses $ dolt sql -q "delete from dolt_query_catalog where id ='Example saved query'"
8
Query OK, 1 row affected
9
us-businesses $ dolt sql -q "select * from dolt_query_catalog"
10
+----+---------------+------+-------+-------------+
11
| id | display_order | name | query | description |
12
+----+---------------+------+-------+-------------+
13
+----+---------------+------+-------+-------------+
14
us-businesses $ dolt sql --save "Example saved query" -q "show tables" -m "You can even add a long description"
15
+----------------+
16
| Table |
17
+----------------+
18
| business_types |
19
| businesses |
20
| naics |
21
| sic |
22
+----------------+
23
us-businesses $ dolt sql -q "select * from dolt_query_catalog"
24
+---------------------+---------------+---------------------+-------------+-------------------------------------+
25
| id | display_order | name | query | description |
26
+---------------------+---------------+---------------------+-------------+-------------------------------------+
27
| Example saved query | 1 | Example saved query | show tables | You can even add a long description |
28
+---------------------+---------------+---------------------+-------------+-------------------------------------+
Copied!
DoltHub displays these queries in the Queries tab of your database for easy use.
Saved Queries
Export as PDF
Copy link
Edit on GitHub