vapor / fluent-postgres-driver

🐘 PostgreSQL driver for Fluent.
MIT License
146 stars 53 forks source link

Sum on `Int` property returns error #92

Closed natanrolnik closed 6 years ago

natanrolnik commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

I suspect https://github.com/vapor/postgresql/pull/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 commented 6 years ago

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

tanner0101 commented 6 years ago

Fixed in PostgreSQL 1.0.2