Skip to content

snowflakedb/gosnowflake

Folders and files

NameName
Last commit message
Last commit date
Mar 7, 2025
Mar 7, 2025
Feb 27, 2025
May 6, 2024
Mar 6, 2025
Dec 10, 2024
Nov 7, 2024
Mar 5, 2021
Apr 18, 2017
Feb 24, 2025
Jan 11, 2022
Feb 25, 2025
Feb 24, 2025
Apr 15, 2024
Nov 7, 2024
Feb 27, 2025
Feb 27, 2025
Dec 9, 2024
Jan 29, 2025
Jan 15, 2024
Feb 25, 2025
Jan 15, 2025
Mar 6, 2025
Jan 15, 2025
Jan 15, 2025
Jan 15, 2025
Jan 15, 2025
Nov 7, 2024
Feb 28, 2025
Nov 7, 2024
May 14, 2024
Jan 17, 2025
Dec 16, 2024
Feb 13, 2025
Feb 13, 2025
Sep 15, 2023
Jan 11, 2022
Feb 27, 2025
Jan 29, 2025
Feb 27, 2025
Oct 26, 2023
Feb 19, 2024
Feb 19, 2024
Jan 17, 2025
Oct 12, 2023
Feb 28, 2025
Nov 27, 2024
Nov 27, 2024
Jan 17, 2025
Feb 28, 2025
Nov 22, 2024
Nov 7, 2024
Feb 27, 2025
Feb 27, 2025
Oct 17, 2023
Sep 20, 2023
Jul 9, 2024
May 21, 2024
Jul 9, 2024
Mar 26, 2024
Jan 11, 2022
Jan 29, 2025
Feb 25, 2025
Oct 23, 2024
Feb 24, 2025
Feb 25, 2025
Feb 25, 2025
Nov 7, 2024
Nov 7, 2024
Nov 7, 2024
Nov 7, 2024
Feb 25, 2025
Jan 11, 2022
Feb 27, 2023
Mar 7, 2025
Mar 7, 2025
Nov 7, 2024
Aug 16, 2023
Nov 28, 2024
Jun 21, 2024
Jan 17, 2025
Dec 20, 2024
Feb 27, 2025
Feb 27, 2025
May 10, 2023
Oct 24, 2024
Oct 30, 2023
Oct 16, 2023
Dec 10, 2024
Dec 16, 2024
Dec 16, 2024
Aug 11, 2023
Aug 16, 2023
May 9, 2024
Nov 7, 2024
Nov 7, 2024
Oct 24, 2024
Apr 19, 2024
Sep 13, 2023
Mar 7, 2025
Jan 17, 2025
Feb 13, 2024
Dec 10, 2024
Dec 10, 2024
Jan 26, 2024
Aug 2, 2023
Nov 7, 2024
Jan 11, 2022
Feb 20, 2025
Dec 10, 2024
Dec 5, 2024
Dec 20, 2024
Jan 11, 2022
Oct 24, 2024
Nov 7, 2024
Dec 4, 2023
Feb 10, 2025
Nov 7, 2024
Jan 29, 2025
Dec 10, 2024
Jan 17, 2025
Dec 20, 2024
Jan 11, 2022
Feb 25, 2025
Feb 5, 2025
Feb 5, 2025
Jan 11, 2022
Dec 4, 2023
Nov 7, 2024
Dec 16, 2024
Feb 24, 2025
Feb 27, 2025
Dec 10, 2024
May 6, 2024
Aug 27, 2024
Feb 28, 2025
Nov 7, 2024
Mar 21, 2023
Feb 28, 2025
Feb 28, 2025
Nov 7, 2024
Mar 4, 2025
Mar 7, 2025

Repository files navigation

Support

For official support and urgent, production-impacting issues, please contact Snowflake Support.

Go Snowflake Driver

Coverage

This topic provides instructions for installing, running, and modifying the Go Snowflake Driver. The driver supports Go's database/sql package.

Prerequisites

The following software packages are required to use the Go Snowflake Driver.

Go

The latest driver requires the Go language 1.22 or higher. The supported operating systems are Linux, Mac OS, and Windows, but you may run the driver on other platforms if the Go language works correctly on those platforms.

Installation

If you don't have a project initialized, set it up.

go mod init example.com/snowflake

Get Gosnowflake source code, if not installed.

go get -u github.com/snowflakedb/gosnowflake

Docs

For detailed documentation and basic usage examples, please see the documentation at godoc.org.

Note

This driver currently does not support GCP regional endpoints. Please ensure that any workloads using through this driver do not require support for regional endpoints on GCP. If you have questions about this, please contact Snowflake Support.

Sample Programs

Snowflake provides a set of sample programs to test with. Set the environment variable $GOPATH to the top directory of your workspace, e.g., ~/go and make certain to include $GOPATH/bin in the environment variable $PATH. Run the make command to build all sample programs.

make install

In the following example, the program select1.go is built and installed in $GOPATH/bin and can be run from the command line:

SNOWFLAKE_TEST_ACCOUNT=<your_account> \
SNOWFLAKE_TEST_USER=<your_user> \
SNOWFLAKE_TEST_PASSWORD=<your_password> \
select1
Congrats! You have successfully run SELECT 1 with Snowflake DB!

Development

The developer notes are hosted with the source code on GitHub.

Testing Code

Set the Snowflake connection info in parameters.json:

{
    "testconnection": {
        "SNOWFLAKE_TEST_USER":      "<your_user>",
        "SNOWFLAKE_TEST_PASSWORD":  "<your_password>",
        "SNOWFLAKE_TEST_ACCOUNT":   "<your_account>",
        "SNOWFLAKE_TEST_WAREHOUSE": "<your_warehouse>",
        "SNOWFLAKE_TEST_DATABASE":  "<your_database>",
        "SNOWFLAKE_TEST_SCHEMA":    "<your_schema>",
        "SNOWFLAKE_TEST_ROLE":      "<your_role>",
        "SNOWFLAKE_TEST_DEBUG":     "false"
    }
}

Install jq so that the parameters can get parsed correctly, and run make test in your Go development environment:

make test

Setting debug mode during tests

This is for debugging Large SQL statements (greater than 300 characters). If you want to enable debug mode, set SNOWFLAKE_TEST_DEBUG to true in parameters.json, or export it in your shell instance.

customizing Logging Tags

If you would like to ensure that certain tags are always present in the logs, RegisterClientLogContextHook can be used in your init function. See example below.

import "github.com/snowflakedb/gosnowflake"

func init() {
    // each time the logger is used, the logs will contain a REQUEST_ID field with requestID the value extracted 
    // from the context
	gosnowflake.RegisterClientLogContextHook("REQUEST_ID", func(ctx context.Context) interface{} {
		return requestIdFromContext(ctx)
	})
}

Setting Log Level

If you want to change the log level, SetLogLevel can be used in your init function like this:

import "github.com/snowflakedb/gosnowflake"

func init() {
    // The following line changes the log level to debug
	_ = gosnowflake.GetLogger().SetLogLevel("debug")
}

The following is a list of options you can pass in to set the level from least to most verbose:

  • "OFF"
  • "error"
  • "warn"
  • "print"
  • "trace"
  • "debug"
  • "info"

Capturing Code Coverage

Configure your testing environment as described above and run make cov. The coverage percentage will be printed on the console when the testing completes.

make cov

For more detailed analysis, results are printed to coverage.txt in the project directory.

To read the coverage report, run:

go tool cover -html=coverage.txt

Submitting Pull Requests

You may use your preferred editor to edit the driver code. Make certain to run make fmt lint before submitting any pull request to Snowflake. This command formats your source code according to the standard Go style and detects any coding style issues.

Runaway dbus-daemon processes on certain OS

This only affects certain Linux distributions, one of them is confirmed to be RHEL. Due to a bug in one of the dependencies (keyring), on the affected OS, each invocation of a program depending on gosnowflake (or any other program depending on the same keyring), will generate a new instance of dbus-daemon fork which can, due to not being cleaned up, eventually fill the fd limits.

Until we replace the offending dependency with one which doesn't have the bug, a workaround needs to be applied, which can be:

  • cleaning up the runaway processes periodically
  • setting envvar DBUS_SESSION_BUS_ADDRESS=$XDG_RUNTIME_DIR/bus (if that socket exists, or create it) or even DBUS_SESSION_BUS_ADDRESS=/dev/null

Details in issue 773