forked from mirror/gorm
Use count(*) instead of count(1) include NULL and non-NULL rows(SQL-92). (#4453)
This commit is contained in:
parent
5b65b02805
commit
a0bddccfe1
|
@ -383,9 +383,9 @@ func (db *DB) Count(count *int64) (tx *DB) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(tx.Statement.Selects) == 0 {
|
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(") {
|
} 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 {
|
if len(tx.Statement.Selects) == 1 {
|
||||||
dbName := tx.Statement.Selects[0]
|
dbName := tx.Statement.Selects[0]
|
||||||
|
|
Loading…
Reference in New Issue