Snowflake Extension for Visual Studio Code

The Snowflake Visual Studio Code (VS Code) extension enables you to write and execute Snowflake SQL statements directly in VS Code. The extension also integrates with Snowpark Python to provide debugging, syntax highlighting, and autocomplete features for SQL in Python code.

You can install the VS Code extension from the Visual Studio marketplace, or you can download and install the .vsix file.

Install the VS Code extension from Visual Studio Marketplace

  1. In VS Code, select Code » Settings » Extensions.

  2. In the Search Extensions in Marketplace field, enter Snowflake, and then select the Snowflake extension.

    To confirm you’ve selected the correct extension, look for the Snowflake badge as shown in the following image:

    The Snowflake certification location. Snowflake certification is a check mark within a blue circle.
  3. Click Install.

Install the VS Code extension from a .vsix file

  1. Download the extension:

    1. Go to https://marketplace.visualstudio.com/items?itemName=snowflake.snowflake-vsc.

    2. Click the Version History tab.

    3. Click Download for the VS Code version you want to install. Note where the file is downloaded.

  2. In VS Code, select Code » Settings » Extensions.

  3. Click More (…) » Install from VSIX.

  4. Browse to the location of the snowflake-x.y.z.vsix file on your computer, select the file, and then select Install.

    After the installation completes, the Snowflake Extension for Visual Studio Code appears in the INSTALLED section of the Extensions menu in VS Code.

Sign in to Snowflake with the VS Code extension

Before you can execute SQL statements or use Snowpark Python features, you must sign in to a Snowflake account.

To sign in to Snowflake with the VS Code extension you can:

  • Use your Snowflake account identifier, username, and password.

  • Use federated authentication such as Security Assertion Markup Language (SAML) or Single sign-on (SSO).

  • Use key-pair authentication.

The first time you use with the VS Code extension to sign in to Snowflake, you’ll need to enter the account identifier for your Snowflake account or the URL that you use to connect to Snowflake. To determine your account identifier, see Account identifiers.

  1. Click the Snowflake icon in the VS Code Activity Bar.

  2. In the Account Identifier/URL field, enter the account identifier for your Snowflake account or the URL that you use to connect to Snowflake, and then click Continue.

    The Account Identifier/URL field isn’t available if you’ve previously provided your Snowflake account credentials.

  3. Select one of the following options in the Auth Method list:

    1. Select Single sign-on to use your SSO credentials to sign in to Snowflake.

    2. Select Username/password to use your Snowflake username and password to sign in to Snowflake.

    3. Select Key Pair to use your Snowflake username and password to sign in to Snowflake. To learn more about key-pair authentication, see Key-pair authentication and key-pair rotation.

  4. Enter your credentials and then click Sign in.

    When you select SSO, a separate authentication page opens after you enter your username and select Sign in with single sign-on. Enter your SSO credentials and then return to VS Code to complete the Snowflake sign in.

    After you successfully sign in, the sidebar displays your account information, your default role, the OBJECT EXPLORER with a Databases list, and your QUERY HISTORY.

The VS Code extension interface

An overview of the Snowflake VS Code extension showing its main areas: the sidebar panel, the SQL panel and the query results panel.

The following table provides descriptions of the VS Code extension interface functional areas.

Item

Description

1

Sidebar panel. Contains the Account, Object Explorer and Query History panes. Use this panel to specify account details, examine database objects, and examine query results.

2

Snowflake SQL panel. Displays Snowflake SQL files.

3

Query History panel. Shows recent queries.

4

Query Results panel. Shows query results. Select a query to display its execution result.

5

Current session. Shows current session information, including current role, database, schema, and active warehouse.

Use the VS Code extension with SnowSQL configuration files

The Snowflake Extension for Visual Studio Code can use Snow SQL configuration files for loading connection configurations.

Note

Only connection configuration values are used. Other SnowSQL configuration values are ignored.

  1. Click the Snowflake icon in the VS Code Activity Bar.

  2. Select Sign in to another account in the Username list.

  3. Select Use SnowSQL Config.

  4. Enter a path to a valid SnowSQL configuration file.

    All connections defined in the configuration display in the Account panel.

Work with SQL files

You can use the Snowflake Extension for Visual Studio Code to create and load SQL files. SQL files are text files that contain one or more SQL statements.

Open or create SQL files

  1. In VS Code, select File » Open, browse to the location of a SQL file, and then open it.

    To create a new SQL file, select File » New File and create a file of type Snowflake SQL File.

  2. Add one or more Snowflake SQL statements to the file.

  3. (Optional) Click Snowflake: Execute All Statements (Execute all statements button) to execute a command.

Execute commands or queries

In VS Code, select one of the following options:

  • To execute all SQL statements in a file, click Snowflake: Execute All Statements (Execute all statements button).

  • To execute a specific command, place your cursor on the statement you want to run and then click Execute.

  • To execute multiple commands, select the statements you want to run and then click Execute. The commands execute in order from top to bottom.

To use keyboard shortcuts to execute statements, select the SQL statements you want to run, press Apple OSX Command key. + [enter] on a Mac keyboard, or Generic control key. + [enter] on a Windows keyboard.

Executed SQL statement results display in the SNOWFLAKE panel.

To cancel in-progress queries, select a query in QUERY HISTORY list and click Cancel query (Cancel query button).

View query history

  1. In VS Code, expand Query History.

  2. Select a statement.

  3. Review the results in the SNOWFLAKE panel.

  4. (Optional) Select one of the following:

    1. Click Snowflake: Copy to Clipboard (Copy query text to clipboard button) to copy the query text to the clipboard.

    2. Click Snowflake: Remove Query (Delete query button) to delete a query.

Work with query results

You can sort, reorder, hide, freeze, or save query results to disk.

  1. In QUERY HISTORY, select a query.

  2. In the SNOWFLAKE panel, choose a column.

  3. Select the expander arrow (↓) and then one of: Sort Ascending, Sort Descending, Hide column “column name”, or Freeze columns up to “column name”.

    If a column was previously hidden, choose any other column and select Unhide N columns.

  4. (Optional) Select one of the following:

    1. Click Cloud (Download results button) to save the results as a a compressed gzip file.

    2. Click Save (Save results button) to save the results as a comma-separated (CSV) file.

Work with Snowpark Python code

You can use the Snowflake Extension for Visual Studio Code to write and debug Snowflake SQL statements in Snowpark Python code.

Debug Snowpark Python functions

  1. Write a Snowflake stored procedure in a Python function where the first parameter is a Snowpark Session object.

  2. An inline Snowflake: Debug option appears above the function name. Choose this option to run the stored procedure in the function, using your current active session through the extension. You can also set debug breakpoints.

Detect SQL statements automatically

To set up automatic SQL syntax highlighting, enable the extension setting Auto Detect Sql in Python. The extension automatically detects SQL statements by looking for a SQL keyword in all capital letters as the first word in a Python string, as shown in the following image.

A code snippet of a Snowflake SQL statement in a Python string showing automatic SQL syntax highlighting.

Denote SQL statements manually

  1. (Optional) Disable the extension setting Auto Detect Sql in Python.

  2. Use comments to denote the start and end of a SQL statement. You can use any combination of the following markers:

    • Start markers: -–startsql, -–beginsql, -–start-sql, -–begin-sql

    • End markers: –-endsql, –-end-sql

    The following image shows how the --begin-sql and --end-sql markers manually denote a SQL statement.

A code snippet of a Snowflake SQL statement in a Python string using comments to manually enable SQL syntax highlighting.

Use SQL autocomplete in Python strings

  1. In a Python file, create a Python string while connected to an active Snowflake session with the VS Code extension.

  2. Write a SQL statement. The autocomplete suggestions appear.

    For example, when you start writing a statement such as SELECT * FROM db1.public, the extension automatically suggests table names.

    Similarly, when you start filling out columns inside a SELECT statement that references a table, the extension automatically suggests column names, as shown in the following image.

A code snippet of a Snowflake SQL statement in a Python string showing autocomplete suggestions for column names.

Jinja template syntax highlighting

By default, the VS Code extension adds basic syntax highlighting and bracket autocomplete for writing Jinja templates in Snowflake SQL, as shown in the following image.

A code snippet of a Snowflake SQL statement with a Jinja template showing syntax highlighting and bracket autocomplete.

Change session context

You can use the Account section of the Side Bar panel to select roles, databases, schemas, and warehouses. Use the associated dropdown to select each as appropriate.

Use the account drop down to sign in to, or switch between different accounts.

Sign in to, or switch between accounts.

Manage stage content

The Snowflake Extension for Visual Studio Code supports managing stage content directly in the Object Explorer.

List all the files in a stage

  1. In the VS Code OBJECT EXPLORER, navigate to a stage.

  2. Expand the stage to see all staged files.

Upload files from the local file system to a stage

The Snowflake Extension for Visual Studio Code only supports uploads for internal stages, all other operations work for both internal and external stages.

  1. In the VS Code OBJECT EXPLORER, navigate to a stage and click Upload (Upload file button).

  2. Enter optional parameters for the upload operation. See PUT for a list of optional parameters.

  3. Navigate to the folder containing upload files, and then select and upload one or more files.

Download files from a stage to a local file system

  1. In the VS Code OBJECT EXPLORER, navigate to a stage.

  2. Click Download (Download results button) to download all files, or expand the stage.

  3. Select and download a file.

  4. Select a directory to complete the download.

Remove files from a stage

See also REMOVE.

  1. In the VS Code OBJECT EXPLORER, navigate to a stage.

  2. Select a file.

  3. Click Remove (Remove button).

VS Code extension settings

The following table lists the Snowflake Extension for Visual Studio Code settings.

Setting

Description

Default

Export CSV » Delimiter

Specifies delimiter for columns

Comma

Export CSV » Header

Enable inclusion of header row in exported CSV file

Enabled

Export CSV » Include Empty Rows

Enable inclusion of empty rows in exported CSV file

Exclude

Export CSV » Quotes

Enable double quotes around all values in exported CSV file

Enabled

Highlight Query

Enable background highlight on the current SQL statement

Enabled

Show Execute Above Statement

Enable a clickable execute action above each statement

Enabled

Snowsql Config Path

If set, connection configuration will be loaded from this file

Unset

Autocomplete Object Details

Show details of a Snowflake object after you select its autocomplete entry

Disabled

Set Client Session Keep Alive

Specifies whether to keep the session active indefinitely as long as the connection is active, regardless of activity. If not enabled, you must sign in again after four hours of inactivity.

Enabled

Autocomplete Variant Keys

Show OBJECT/VARIANT key autocomplete suggestions

Disabled

Object Explorer: Search

Enable search in object explorer

Enabled

Query History: Item Limit

Specifies the maximum number of queries shown in history. Showing more queries might affect performance.

1000

VS Code extension preview settings

The following table lists the VS Code extension preview settings.

Setting

Description

Default

Syntax Highlighting: Auto Detect Sql in Python

Enable automatic syntax highlighting of SQL statements in Python strings

Enabled

Enable Public Preview Features

Enable public preview features for the extension

Disabled

Change VS Code extension settings

  1. Select one of the following:

    1. On Windows/Linux select File » Preferences » Settings.

    2. On macOS select Code » Settings » Settings.

  2. In the Search settings field, enter Snowflake.

  3. Select the User or Workspace tabs to view or modify user specific or workspace specific settings.

  4. Close the Settings tab.

Show the VS Code extension changelog

  1. Press CMD+Shift+P (Mac), or CTRL+Shift+P (Windows).

  2. Enter the following command:

    Show Change Log
    
    Copy

Uninstall the VS Code extension

  1. Select Code » Settings » Extensions

  2. Select the extension.

  3. Right-click and select Disable or Uninstall.