top of page

Why Does a SQL Completion Rate Show Zero When Some Work Is Finished?

Oct 26
3 min read

Three of eight tasks are complete, but a dashboard shows zero percent. The source records are present, the count looks correct, and multiplying the answer by one hundred changes nothing. Before investigating the chart, inspect the arithmetic and the data types at the point where division happens.


The problem can arise when both operands are integers. A calculation may discard the fractional part before a later formatting step ever sees it. Adding decimal places to the final display cannot recover information that the earlier arithmetic has already removed.


Review the expression from the inside out


PostgreSQL documents integer division as truncating toward zero. With integer operands, 3 / 8 yields 0. Dividing as numeric values produces a fractional result instead.


For an illustrative PostgreSQL expression, completed_count::numeric / total_count performs numeric division when total_count is an integer. Multiplying that fraction by 100 gives the percentage. The cast belongs before division; casting the already truncated result is too late.


Inspect calculated columns, database views and application transformations as well as the final query. A rate can be damaged upstream and then carried through several perfectly functioning layers.


Use a fixture with an unmistakable result


Illustrative example: three of eight


The mathematical fraction is 3 divided by 8, or 0.375. As a percentage, it is 37.5%. Record these as separate expected values if one system stores fractions and another displays percentages.


Test zero of eight, eight of eight and three of eight. Expected fractions are 0, 1 and 0.375. This catches a fix that makes the middle case look right while accidentally scaling every result twice.


Check a value that needs rounding


One of three is a repeating decimal. Decide whether the user-facing report should display 33.3%, 33.33% or another precision. Keep the unrounded value available for subsequent calculations where practical.


Formatting and calculation are different stages. Rounding each subgroup's displayed rate and then averaging those displays can create another error. Use the original counts when producing an overall rate with a different population.


Define the zero-denominator policy


A rate for zero completed tasks out of zero total tasks is not established by the arithmetic alone. It may mean there was no eligible work, the source has not loaded, or the population definition is wrong.


An illustrative guard using PostgreSQL's NULLIF expression, such as completed_count::numeric / NULLIF(total_count, 0) avoids dividing by zero by producing a missing result. It does not decide what the reader should see. Choose a label such as “No eligible tasks” only when the data actually supports that interpretation.


Do not convert all missing rates to zero. Zero percent suggests an observed population with no completions, which differs from an absent population. Preserve the reason for an unavailable rate when the reporting system can represent it.


Verify the boundary between storage and display


Write a short contract: the stored rate is a fraction between zero and one, or the stored value is a percentage between zero and one hundred. State which component performs scaling and formatting.


Then inspect one real record across each layer: the database value, API representation and rendered label. If the API returns 0.375 and the page shows 0.375%, the calculation is correct but the display contract is wrong. If it returns 37.5 and the page shows 3,750%, scaling happened twice.


Also check whether the numerator can exceed the denominator. If it can, the populations may be mismatched or the metric may not be a completion rate at all. Do not hide that condition by clipping the output to one hundred percent.


Make the correction reviewable


Keep the original expression, corrected expression, operand types and fixture results in the change record. Explain the intended meaning of an unavailable rate alongside the successful examples. A reviewer should not need access to the production dashboard to understand the fix.


See the guide on when to round operational measurements for the next boundary. A useful FutureOS brief includes both raw counts and the expected display, so collaborators can distinguish arithmetic, population and presentation issues.


Editorial note


Editorial note: This article was prepared with AI assistance. Primary sources and the linked FutureOS article inventory were checked on October 26, 2026. Examples are illustrative and are not customer results. The current FutureOS introduction describes the project as being in prelaunch; this guide does not assert that a particular product feature, integration or service is available. The procedures are practical proposals to adapt and test in your own setting. No independent expert review is claimed. Start with a specific question, your relevant constraints and a small example of the result you need.


Comments


Commenting on this post isn't available anymore. Contact the site owner for more info.
bottom of page