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

  1. With an open file, select the queries you want to run.
  2. Select SQLTools: Run Query from command palette.
  3. Wait for the results to show up.

Running from bookmarks

  1. Select SQLTools Bookmarks: Run from command palette.
  2. Pick the query you want from the list.
  3. Wait for the results to show up.

Running from history

  1. Select SQLTools History: Run from command palette.
  2. Pick the query you want from the list.
  3. 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.