ghetzel / pivot

An extensible database abstraction service, written in Golang.
GNU Lesser General Public License v2.1
66 stars 5 forks source link

Error using the Count SQL aggregator #8

Closed smichaku closed 6 years ago

smichaku commented 6 years ago

Using the Count SQL aggregator with postgres backend (and perhaps others) results in the following error:

count, err := database.transitions.Count(filter.All())

pq: column "*" does not exist

This may be fixed by replacing the "*" field with the collection's identity field:

diff --git a/backends/sql-aggregator.go b/backends/sql-aggregator.go
index 4b1df58..4e2b362 100644
--- a/backends/sql-aggregator.go
+++ b/backends/sql-aggregator.go
@@ -18,7 +18,7 @@ func (self *SqlBackend) Sum(collection *dal.Collection, field string, f ...*filt
 }

 func (self *SqlBackend) Count(collection *dal.Collection, f ...*filter.Filter) (uint64, error) {
-       v, err := self.aggregateFloat(collection, filter.Count, `*`, f)
+       v, err := self.aggregateFloat(collection, filter.Count, collection.IdentityField, f)
        return uint64(v), err
 }
ghetzel commented 6 years ago

Good find, thank you!