Executing Queries
Executing Queries
You have 3 methods to execute queries. Run from selection, run from bookmarks, run from history.
TIP: You can also set a connection to run queries against it in the first line of the file using -- @conn ConnectionName.
Running from a file/selection
- With an open file, select the queries you want to run.
- Select
SQLTools: Run Queryfrom command palette. - Wait for the results to show up.
Running from bookmarks
- Select
SQLTools Bookmarks: Runfrom command palette. - Pick the query you want from the list.
- Wait for the results to show up.
Running from history
- Select
SQLTools History: Runfrom command palette. - Pick the query you want from the list.
- Wait for the results to show up.
Queries with parameters
It also supports query string replacements with parameters either defined in variables or
provided with inputBoxes.
To enable query parameters replacements, you need to provide some additional configs.
In in your workspaceFolder, edit the file .vscode/settings.json. Make sure that you have
the following parameters enabled:
"sqltools.queryParams.enableReplace": false, // enables string replacement.
// the following regex, will match named params in your variables files
"sqltools.queryParams.regex": "\\$[\\d]+|([@:$][\\w]+)",
// a connection example...
"sqltools.connections": [
{
"previewLimit": 50,
"server": "localhost",
"port": 5432,
"driver": "PostgreSQL",
"name": "MyDb",
"group": "Locals",
"database": "world-db",
"username": "world",
"password": "world123",
"askForPassword": false,
"variables": {
":name": "'%e%'",
}
}
]
In this case, when you execute your query, every word that matches :name will
be automatically replaced for '%e%'. But if you have a param like $1, itโll
ask you for it every time.
NOTE: this is just a string replacement, and therefore, you can execute subqueries using this replacement. You can also change the query columns/filters itself.
TIP: You can also set parameters for a query by preceding it with comment lines -- @var :name = '%e%'. Parameter values set in comments take priority over values set in the connection definition.