jackc/pgx · error

cannot scan into *pgtype.DriverBytes from QueryRow

Error message

cannot scan into *pgtype.DriverBytes from QueryRow

What it means

connRow.Scan (QueryRow) rejects *pgtype.DriverBytes destinations up front: DriverBytes is a zero-copy view into the connection's internal read buffer that is only valid while the Rows are open, and QueryRow scans and closes the rows in one shot — returning such a view would hand back freed memory.

Solutions

  1. Scan into []byte or string instead, which copies the data
  2. Use Query plus rows.Next/rows.Scan when zero-copy DriverBytes is required
  3. Allocate an owned type for the column and scan into that
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at rows.go:105 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of jackc/pgx@ec1a0befd2 (2026-08-04). Data as JSON: /api/errors/ab72fbdd08884dd1. Report an issue: GitHub.

Appendix: source

Thrown at rows.go:105

type RowScanner interface {
	// ScanRows scans the row.
	ScanRow(rows Rows) error
}

// connRow implements the Row interface for Conn.QueryRow.
type connRow baseRows

func (r *connRow) Scan(dest ...any) (err error) {
	rows := (*baseRows)(r)

	if rows.Err() != nil {
		return rows.Err()
	}

	for _, d := range dest {
		if _, ok := d.(*pgtype.DriverBytes); ok {
			rows.Close()
			return fmt.Errorf("cannot scan into *pgtype.DriverBytes from QueryRow")
		}
	}

	if !rows.Next() {
		if rows.Err() == nil {
			return ErrNoRows
		}
		return rows.Err()
	}

	rows.Scan(dest...)
	rows.Close()
	return rows.Err()
}

// baseRows implements the Rows interface for Conn.Query.
type baseRows struct {
	typeMap      *pgtype.Map

View on GitHub (pinned to ec1a0befd2)