Databricks SQL Driver for Go


This article covers the Databricks SQL Driver for Go, which is provided as-is and is not supported by Databricks through customer technical support channels. Questions and feature requests can be communicated through the Issues page of the databricks/databricks-sql-go repo on GitHub.

The Databricks SQL Driver for Go is a Go library that allows you to use Go code to run SQL commands on Databricks compute resources.


Specify the DSN connection string

The Databricks SQL Driver for Go uses a data source name (DSN) connection string to access clusters and SQL warehouses. To specify the DSN connection string in the correct format, use the following syntax, where:

  • [your token] is your Databricks personal access token from the requirements.

  • [Workspace hostname] is the Server Hostname value from the requirements.

  • [Endpoint HTTP Path] is the HTTP Path value from the requirements.

databricks://:[your token]@[Workspace hostname][Endpoint HTTP Path]

For example, for a cluster:


For example, for a SQL warehouse:



As a security best practice, you should not hard-code this DSN connection string into your Go code. Instead, you should retrieve this DSN connection string from a secure location. For example, the code example later in this article uses an environment variable.

Query data

The following code example demonstrates how to call the Databricks SQL Driver for Go to run a basic SQL query on a Databricks compute resource. This command returns the first two rows from the diamonds table.

The diamonds table is included in Sample datasets. This table is also featured in Tutorial: Query data with notebooks.

This code example retrieves the DSN connection string from an environment variable named DATABRICKS_DSN.

package main

import (

  _ ""

func main() {
  dsn := os.Getenv("DATABRICKS_DSN")

  if dsn == "" {
    panic("No connection string found." +
          "Set the DATABRICKS_DSN environment variable, and try again.")

  db, err := sql.Open("databricks", dsn)

  if err != nil {

  var (
    _c0     string
    carat   string
    cut     string
    color   string
    clarity string
    depth   string
    table   string
    price   string
    x       string
    y       string
    z       string

  rows, err := db.Query("SELECT * FROM LIMIT 2")

  if err != nil {

  defer rows.Close()

  for rows.Next() {
    err := rows.Scan(&_c0,

    if err != nil {

    fmt.Print(_c0, ",",
      carat, ",",
      cut, ",",
      color, ",",
      clarity, ",",
      depth, ",",
      table, ",",
      price, ",",
      x, ",",
      y, ",",
      z, "\n")

  err = rows.Err()

  if err != nil {



For additional examples, see the examples folder in the databricks/databricks-sql-go repository on GitHub.

Additional resources