From 3d87575e7efd2b42d6f02b5b04a8179d49b46073 Mon Sep 17 00:00:00 2001 From: Jinzhu Date: Mon, 18 Jan 2021 19:43:04 +0800 Subject: [PATCH] make Count compatible with Select with Count func, close #3962 --- finisher_api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/finisher_api.go b/finisher_api.go index 528f32be..e757bfe9 100644 --- a/finisher_api.go +++ b/finisher_api.go @@ -378,7 +378,7 @@ 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)"}}) - } else if !strings.Contains(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)"} if len(tx.Statement.Selects) == 1 {