Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregate does not allow to get a float (decimal) value #342

Open
skolodyazhnyy opened this issue Aug 23, 2023 · 2 comments
Open

Aggregate does not allow to get a float (decimal) value #342

skolodyazhnyy opened this issue Aug 23, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@skolodyazhnyy
Copy link
Contributor

skolodyazhnyy commented Aug 23, 2023

Aggregate API returns an integer, how do I aggregate a float field?

For instance, I have a decimal price field in my database and I would like to find a sum of all prices:

total, err := repo.Aggregate(ctx, rel.From("products"), "SUM", "price")

Instead of getting a sum I'm getting an error

sql: Scan error on column index 0, name "result": converting driver.Value type []uint8 ("1.00000000") to a int64: invalid syntax

Field price has type DECIMAL in MySQL database.

@Fs02
Copy link
Member

Fs02 commented Aug 26, 2023

maybe you can use raw query as workaround?

var result struct {Sum float64}
sql := rel.SQL("SELECT ....")
err := repo.Find(ctx, &result, sql)

@skolodyazhnyy
Copy link
Contributor Author

skolodyazhnyy commented Aug 26, 2023

Not really, because result requires primary ID 😄

Finally, after go-rel/primaryreplica#26 got merged, I could make request using sql connection directly. Still would be nice to be able to aggregate on decimal fields.

@lafriks lafriks added the enhancement New feature or request label Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants