I failing to understand why I can not scan single value to "count" variable.
Could anyone explain what am i doing wrong? Single column value is returned and I try to scan it to integer variable.
query := `
SELECT COUNT('*') FROM "some-table"
WHERE (("state" = 'state') AND ("id" = 1))`
rows, err := s.conn.Query(ctx, query)
defer rows.Close()
var count int
err = rows.Scan(&count)
if err != nil {
return false, fmt.Errorf("execute query: %w", err)
}
Returns error:
execute query: number of field descriptions must equal number of values, got 1 and 0"
UPDATE: I made workaround with thing below, but not sure it the right way:
count, err := pgx.CollectOneRow(rows, pgx.RowTo[int])