How Do I SUM() in SQLite? #4346
Replies: 1 comment 2 replies
-
Because that's how this function is defined my most database implementations. SQLite is a bit a special case there,it's technically not 100% correct to use that implementation, but on the other hand SQLite really does not have a hard type system at all and will just accept that we ask for a numeric value there.
That's not true, see the SQLite documentation for details (Point 3) To answer the original question: With diesel you always need to use the right rust type for your SQL types. That's checked at compile time and you get such an error if the types do not match. In this case you need to use a type that compatible with |
Beta Was this translation helpful? Give feedback.
-
I'm trying to get both a count of rows and a sum of a column from a table in SQLite. Ideally, I'd like to do this in one call, but for now I can't even get the sum portion to work.
For count, I have this:
This seems to work just fine. For sum, I was trying this:
The column
total
is defined as aBIGINT NOT NULL
column, which ends up asBigInt
(i64) in theschema.rs
. What I am not understanding is the error I get:Why does it want to use
diesel::sql_types::Numeric
when the column isBigInt
? On top of that, I don't even think that SQLite uses Numeric, as the docs say to use Double. But I don't really know how to get sum to use that instead (or more preferably, BigInt/i64).Any help on this would be greatly appreciated!
Beta Was this translation helpful? Give feedback.
All reactions