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

Sum on Int property returns error #92

Closed
natanrolnik opened this issue Aug 22, 2018 · 4 comments
Closed

Sum on Int property returns error #92

natanrolnik opened this issue Aug 22, 2018 · 4 comments

Comments

@natanrolnik
Copy link

natanrolnik commented Aug 22, 2018

Assuming I have the following model that conforms to PostgreSQLStringModel:

final class Transaction: Codable {
    var id: String?
    var amount: Int
}

Calling:
return Transaction.query(on: req).sum(\.amount)

Gives the following error:
Could not decode Int: 0x0001000000000000000e (NUMERIC).

I'm doing something wrong? The .sum method should return the sum for all the properties on that column, correct? Btw, the error when the table was empty was different than the error when the table had some records in it.

@tanner0101
Copy link
Member

tanner0101 commented Sep 8, 2018

Could not decode Int: 0x0001000000000000000e (NUMERIC).

This seems like a bug in https://github.com/vapor/postgresql. (Looking into it)

Btw, the error when the table was empty was different than the error when the table had some records in it.

This is a Fluent thing. You should check that the query count returns > 0 before trying to run aggregates.

@tanner0101
Copy link
Member

I suspect vapor/postgres-kit#102 will fix, but won't be able to test for a bit. You can try by doing:

swift package edit PostgreSQL --revision numeric-int

@natanrolnik
Copy link
Author

natanrolnik commented Sep 8, 2018

Just tested, and that PR indeed solves the issue! Thanks Tanner.

@tanner0101
Copy link
Member

Fixed in PostgreSQL 1.0.2

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

No branches or pull requests

2 participants