SUM computes the total over a specific column:
SELECT SUM(rating) FROM mock_items
WHERE id @@@ paradedb.all();
The field being summed, in this case rating, must be indexed as fast.
By default, SUM ignores null values. Use COALESCE to include them in the final sum:
SELECT SUM(COALESCE(rating, 0)) FROM mock_items
WHERE id @@@ paradedb.all();
To verify that SUM was pushed down, look for a ParadeDB Aggregate Scan with sum in the EXPLAIN output:
EXPLAIN SELECT SUM(rating) FROM mock_items
WHERE id @@@ paradedb.all();
Expected Response
                                               QUERY PLAN
--------------------------------------------------------------------------------------------------------
 Custom Scan (ParadeDB Aggregate Scan) on mock_items  (cost=0.00..0.00 rows=0 width=8)
   Index: search_idx
   Tantivy Query: {"with_index":{"query":"all"}}
   Aggregate Definition: {"0":{"sum":{"field":"rating"}},"_doc_count":{"value_count":{"field":"ctid"}}}
(4 rows)