Skip to main content
2 of 2
tag, minor edits
Erwin Brandstetter
  • 182.1k
  • 28
  • 457
  • 620

Postgres SUM over PARTITION BY "tolerate" null values

I have a view which calculates rolling sum taking in value form previous row based on PARTITION BY clause, and I need to indicate one field in PARTITION BY clause can have nulls in them.

sum(s."QuantityChange") OVER (PARTITION BY s."LocationId", s."PartId", s."SupplierFacilityId" ORDER BY s."DueDate" ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS "RunningSum"

Sometimes SupplierFacilityId is null and that's fine, it should still be included in the sum() calculation.

Is this possible with Postgres?

vmachacek
  • 103
  • 1
  • 4