You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
.sum() get error if all values of at a group is zero [ ERROR ] PostgreSQLError.decode: Could not decode Int: 0x0000000000000000 (NUMERIC). (ErrorMiddleware.swift:26)
[psql] [2018-10-07 20:37:19 +0000] SELECT "TestTable"."name", SUM("TestTable"."score") AS "score" FROM "TestTable" GROUP BY "TestTable"."name" ORDER BY "TestTable"."name" ASC [][ ERROR ] PostgreSQLError.decode: Could not decode Int: 0x0000000000000000 (NUMERIC). (ErrorMiddleware.swift:26)[WARNING] [Async] [QueueHandler] Read triggered when input queue was empty, ignoring: close(PostgreSQL.PostgreSQLMessage.CloseResponse.statement(name: "ELECT 3")).
The text was updated successfully, but these errors were encountered:
It seems the Fluent have a problem to work with PostgreSQL's numeric type when value is zero
The .sum() function upper type from int8 to numeric - because int8 + int8 not adjusted to int8 size. So, workaround is change type from Int8 to lower, for example to PostgreSQLDataType.int4 or .int2. In this case result will be int8 or int4, which no have problem with zero. Sure, if that is applicable to your situation.
workaround example
extensionTestTable:Migration{publicstaticfunc prepare(on connection:PostgreSQLConnection)->Future<Void>{returnPostgreSQLDatabase.create(self, on: connection){ builder in
builder.field(for: \.id, isIdentifier: true)
builder.field(for: \.name)
builder.field(for: \.score, type:PostgreSQLDataType.int4)}}}
TL;DR
.sum()
get error if all values of at a group is zero[ ERROR ] PostgreSQLError.decode: Could not decode Int: 0x0000000000000000 (NUMERIC). (ErrorMiddleware.swift:26)
Explain:
The text was updated successfully, but these errors were encountered: