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

This commit is contained in:
Tony 2021-06-11 21:51:18 +08:00 committed by GitHub
parent 5b65b02805
commit a0bddccfe1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 2 deletions

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]