---
source: https://iinventedlight.com/library/notes/go-database-sql.md
title: "Go database/sql: a generic interface around SQL drivers"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (Go docs); BSD-3-Clause (Go source); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "Summary by iinventedlight (AI-assisted). Sources: Go docs, database/sql package; Go source, sql.go. 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-18
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-18
as_of: 2026-11-18
confidence: medium
untested: "Not reproduced (2026-11-18). 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"
tags: [go, sql, database, driver, query]
client: Librarian
sources:
  - id: S1
    title: "database/sql package"
    publisher: Go docs
    url: https://pkg.go.dev/database/sql
    accessed: 2026-11-18
    license: "BSD-3-Clause"
  - id: S2
    title: "sql.go"
    publisher: Go source
    url: https://raw.githubusercontent.com/golang/go/master/src/database/sql/sql.go
    accessed: 2026-11-18
    license: "BSD-3-Clause"
---
# Go database/sql: a generic interface around SQL drivers
**Answer:** Package sql is a generic interface around SQL or SQL-like databases, and it must be paired with a database driver. QueryContext runs a query that returns rows (typically a SELECT). Args fill any placeholder parameters in that query.

## Examples

```go
package main
import (
    "context"
    "database/sql"
)

func list(ctx context.Context, db *sql.DB) (*sql.Rows, error) {
    return db.QueryContext(ctx, "SELECT id FROM items")
}
```

## Notes

Import a driver and then use a DB. If a driver does not support context cancellation, it returns only after the query is completed.

## Reference list

- `The` sql package is a generic interface around SQL databases.
- `The` package must be used with a database driver.
- `QueryContext` runs a query that returns rows, typically a SELECT.

## See also

- [go-context](https://iinventedlight.com/library/notes/go-context/)
- [go-error-handling](https://iinventedlight.com/library/notes/go-error-handling/)
- [go-modules-basics](https://iinventedlight.com/library/notes/go-modules-basics/)

## Claims

- id: C1
  claim: The sql package is a generic interface around SQL databases.
  source: S1
  evidence: "Package sql provides a generic interface around SQL"

- id: C2
  claim: The package must be used with a database driver.
  source: S2
  evidence: "The sql package must be used in conjunction with a database driver"

- id: C3
  claim: QueryContext runs a query that returns rows, typically a SELECT.
  source: S2
  evidence: "QueryContext executes a query that returns rows, typically a SELECT"

## Sources

- [S1] database/sql package. Go docs. https://pkg.go.dev/database/sql . License: BSD-3-Clause. Accessed 2026-11-18.

- [S2] sql.go. Go source. https://raw.githubusercontent.com/golang/go/master/src/database/sql/sql.go . License: BSD-3-Clause. Accessed 2026-11-18.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go docs, database/sql package; Go source, sql.go. 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).
