{"record":{"id":"ab72fbdd08884dd1","repo":"jackc/pgx","slug":"cannot-scan-into-pgtype-driverbytes-from-queryrow","errorCode":null,"errorMessage":"cannot scan into *pgtype.DriverBytes from QueryRow","messagePattern":"cannot scan into \\*pgtype\\.DriverBytes from QueryRow","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"rows.go","lineNumber":105,"sourceCode":"type RowScanner interface {\n\t// ScanRows scans the row.\n\tScanRow(rows Rows) error\n}\n\n// connRow implements the Row interface for Conn.QueryRow.\ntype connRow baseRows\n\nfunc (r *connRow) Scan(dest ...any) (err error) {\n\trows := (*baseRows)(r)\n\n\tif rows.Err() != nil {\n\t\treturn rows.Err()\n\t}\n\n\tfor _, d := range dest {\n\t\tif _, ok := d.(*pgtype.DriverBytes); ok {\n\t\t\trows.Close()\n\t\t\treturn fmt.Errorf(\"cannot scan into *pgtype.DriverBytes from QueryRow\")\n\t\t}\n\t}\n\n\tif !rows.Next() {\n\t\tif rows.Err() == nil {\n\t\t\treturn ErrNoRows\n\t\t}\n\t\treturn rows.Err()\n\t}\n\n\trows.Scan(dest...)\n\trows.Close()\n\treturn rows.Err()\n}\n\n// baseRows implements the Rows interface for Conn.Query.\ntype baseRows struct {\n\ttypeMap      *pgtype.Map","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/jackc/pgx/blob/ec1a0befd22592cffffdeeb0a50311b506372f4c/rows.go#L87-L123","documentation":"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.","triggerScenarios":"Thrown at rows.go:105 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Scan into []byte or string instead, which copies the data","Use Query plus rows.Next/rows.Scan when zero-copy DriverBytes is required","Allocate an owned type for the column and scan into that"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ec1a0befd22592cffffdeeb0a50311b506372f4c","analyzedAt":"2026-08-04T22:52:11.263Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}