Use count(*) instead of count(1) include NULL and non-NULL rows(SQL-92).

This commit is contained in:
Tony Pang 2021-06-10 15:48:45 +08:00
parent 50e85e14d4
commit b7fb319765

View File

@ -383,9 +383,9 @@ func (db *DB) Count(count *int64) (tx *DB) {
}
if len(tx.Statement.Selects) == 0 {
tx.Statement.AddClause(clause.Select{Expression: clause.Expr{SQL: "count(1)"}})
tx.Statement.AddClause(clause.Select{Expression: clause.Expr{SQL: "count(*)"}})
} else if !strings.HasPrefix(strings.TrimSpace(strings.ToLower(tx.Statement.Selects[0])), "count(") {
expr := clause.Expr{SQL: "count(1)"}
expr := clause.Expr{SQL: "count(*)"}
if len(tx.Statement.Selects) == 1 {
dbName := tx.Statement.Selects[0]