From c1b0a01ca75ac9eb3a7dbc1396f583ab5dbf9557 Mon Sep 17 00:00:00 2001 From: Felix <23635466+its-felix@users.noreply.github.com> Date: Sun, 3 Mar 2024 07:30:22 +0100 Subject: [PATCH] Fix behavior of CollectRows to return empty slice if Rows are empty https://github.com/jackc/pgx/issues/1924 --- rows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rows.go b/rows.go index 17e36cba2..78ef5326a 100644 --- a/rows.go +++ b/rows.go @@ -438,7 +438,7 @@ func AppendRows[T any, S ~[]T](slice S, rows Rows, fn RowToFunc[T]) (S, error) { // CollectRows iterates through rows, calling fn for each row, and collecting the results into a slice of T. func CollectRows[T any](rows Rows, fn RowToFunc[T]) ([]T, error) { - return AppendRows([]T(nil), rows, fn) + return AppendRows([]T{}, rows, fn) } // CollectOneRow calls fn for the first row in rows and returns the result. If no rows are found returns an error where errors.Is(ErrNoRows) is true.