---
sidebar_position: 1
title: Go driver
description: Connect to MotherDuck from Go applications using the go-duckdb driver.
---
The [go-duckdb driver](https://github.com/duckdb/duckdb-go) supports MotherDuck out of the box!

To connect, you need a dependency on the driver in your `go.mod` file:

```go
github.com/duckdb/duckdb-go/v2 v2.5.1
```

Your code can then open a connection using the standard [database/sql](https://pkg.go.dev/database/sql) package, or any other mechanisms supported by [go-duckdb](https://github.com/duckdb/duckdb-go/blob/master/README.md):

```go
db, err := sql.Open("duckdb", "md:my_db?motherduck_token=<token>")
```

## Go Gotchas

### Use "motherduck_" prefixed configuration in the connection string

Because `duckdb-go` parses all arguments out into a configuration dictionary, the shorthand properties such as `attach_mode` will not work.
Use the fully qualified properties such as `motherduck_attach_mode` for the MotherDuck-specific properties:

```go
db, err := sql.Open("duckdb", "md:my_db?motherduck_attach_mode=single")
```


### Connecting to multiple accounts from the same process

Because `duckdb-go` parses all arguments out into a configuration dictionary, trying to connect with multiple MotherDuck accounts (different `motherduck_token` values) from the same Go process will fail with [Can't open a connection to same database file with a different configuration](/documentation/troubleshooting/error_messages.md#disallowed-connections-with-a-different-configuration).
If connecting to different accounts is a requirement, work around this by connecting to an in-memory DuckDB database first:

```go
c, err := duckdb.NewConnector(":memory:?custom_user_agent=INTEGRATION_NAME/v1.2.3", func(execer driver.ExecerContext) error {
		bootQueries := []string{
			`INSTALL motherduck`,
			`LOAD motherduck`,
			fmt.Sprintf("SET motherduck_token='%s'", token),
			`SET motherduck_session_hint='user123'`,
			`ATTACH 'md:my_db'`,
		}
		for _, query := range bootQueries {
			_, err := execer.ExecContext(context.Background(), query, nil)
			if err != nil {
				return err
			}
		}
		return nil
	})
	if err != nil {
		// handle the error
	}
	defer c.Close()
	db := sql.OpenDB(c)
	defer db.Close()
```
