---
source: https://iinventedlight.com/library/notes/go-database-sql-driver.md
title: "Go database/sql/driver: interfaces implemented by database drivers"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (The Go Authors); BSD-3-Clause (The Go Authors); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: The Go Authors, driver package - database/sql/driver; The Go Authors, driver.go (source). BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-systems: go-database-sql-driver"
tags: [go, database, sql, driver, connector]
client: Librarian
sources:
  - id: S1
    title: "driver package - database/sql/driver"
    publisher: The Go Authors
    url: https://pkg.go.dev/database/sql/driver
    accessed: 2026-11-26
    license: "BSD-3-Clause"
  - id: S2
    title: "driver.go (source)"
    publisher: The Go Authors
    url: https://go.dev/src/database/sql/driver/driver.go
    accessed: 2026-11-26
    license: "BSD-3-Clause"
---
# Go database/sql/driver: interfaces implemented by database drivers
**Answer:** The driver package defines interfaces that a database driver must implement for database/sql; most programs should import database/sql instead of this package.

## Which interfaces a driver should implement

The driver interface has changed over time.

Drivers should implement Connector and DriverContext.

The Connect and Open methods on Connector and Driver should never return ErrBadConn.

ErrBadConn is only appropriate from Validator, SessionResetter, or a query method when the connection is already invalid, for example already closed.

Even if the server sends back an error, you should not return ErrBadConn, and errors are checked with errors.Is.

Every Conn should implement Pinger, SessionResetter, and Validator.

If the driver supports named parameters or context, Conn should also implement ExecerContext, QueryerContext, ConnPrepareContext, and ConnBeginTx.

Implement NamedValueChecker when you need custom data types.

CheckNamedValue can also drop a per-query option by returning ErrRemoveArgument.

Drivers that expose more than one result set should implement RowsNextResultSet on Rows.

A row value may itself return a Rows type, and that can represent a database cursor value.

## Pooling, sessions, and value conversion

When a Conn implements Validator, IsValid is called before the connection is returned to the pool.

When a pool entry implements SessionResetter, ResetSession is called before that connection is reused for another query.

If a connection is reused immediately and never returns to the pool, ResetSession still runs, but IsValid does not.

Bool is a ValueConverter that converts input values to bool.

DefaultParameterConverter returns the argument unchanged when IsValue(arg) is true.

Otherwise, if the argument implements Valuer, its Value method supplies the Value.

If the argument is a nil pointer, ConvertValue returns a nil Value. If the also argument is a non-nil pointer, it is dereferenced and ConvertValue is called recursively.

## See also

- [go-database-sql](https://iinventedlight.com/library/notes/go-database-sql/)
- [go-errors](https://iinventedlight.com/library/notes/go-errors/)
- [go-context](https://iinventedlight.com/library/notes/go-context/)

## Claims

- id: C1
  claim: Ordinary application code should use database/sql, not this package.
  source: S1
  evidence: "Most code should use the database/sql package."

- id: C2
  claim: Open and Connect must not return ErrBadConn.
  source: S1
  evidence: "The Connector.Connect and Driver.Open methods should never return ErrBadConn"

- id: C3
  claim: Open creates a new database connection.
  source: S2
  evidence: "Open returns a new connection to the database."

## Sources

- [S1] driver package - database/sql/driver. The Go Authors. https://pkg.go.dev/database/sql/driver . License: BSD-3-Clause. Accessed 2026-11-26.

- [S2] driver.go (source). The Go Authors. https://go.dev/src/database/sql/driver/driver.go . License: BSD-3-Clause. Accessed 2026-11-26.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: The Go Authors, driver package - database/sql/driver; The Go Authors, driver.go (source). BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
