Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

Count function error #1395

Open
w570955342 opened this issue Aug 17, 2019 · 5 comments
Open

Count function error #1395

w570955342 opened this issue Aug 17, 2019 · 5 comments

Comments

@w570955342
Copy link

sql: Scan error on column index 0, name "COUNT(*)": converting driver.Value type float64 ("1.159454e+06") to a int64: invalid syntax

@w570955342
Copy link
Author

count 函数返回值类型是 int64,但是当查回的数据量过大时,会用科学计数法表示,然后 float64 转化int64 失败,怎么解决?

@lunny
Copy link
Member

lunny commented Aug 17, 2019

Could you paste your code here?

@w570955342
Copy link
Author

w570955342 commented Aug 19, 2019

@lunny

if withCount, ok := query["withCount"]; ok {
		if w, ok := withCount.(bool); ok {
			if w {
				total, err := session.Count(query["model"])
				if err != nil {
					return errors.New("Count函数错误" + err.Error())
				} else {
					*count = total
				}
			}
		} else {
			return errors.New("withCount格式不正确")
		}
	}

@lunny
Copy link
Member

lunny commented Aug 19, 2019

It seems session.Count(query["model"]) isn't supported.

@w570955342
Copy link
Author

@lunny 问题好像不是出现在这里,如果我加上筛选条件,count函数返回的总数不是那么大,就能正常返回结果,不会报错。只有count函数返回的总数特别大的时候,默认会使用科学计数法表示,然后再转化成int64,就出现了上述错误。我目前是把count函数的返回值类型 int64 改成了 float64,然后count函数就能正常返回结果。

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants