Explain seemingly redundant rows.Close() in CollectOneRow

fixes https://github.com/jackc/pgx/issues/2282
This commit is contained in:
Jack Christensen 2025-03-21 20:33:32 -05:00
parent 70c9a147a2
commit 05fe5f8b05

View File

@ -473,6 +473,8 @@ func CollectOneRow[T any](rows Rows, fn RowToFunc[T]) (T, error) {
return value, err
}
// The defer rows.Close() won't have executed yet. If the query returned more than one row, rows would still be open.
// rows.Close() must be called before rows.Err() so we explicitly call it here.
rows.Close()
return value, rows.Err()
}