01003WARNINGTier 3 — Handle with care✅ HIGH confidencenull value eliminated in set function
What this means
SQLSTATE 01003 is issued when an aggregate function (e.g., SUM, AVG, COUNT) silently ignores NULL values in its input set. This matches standard SQL behaviour but is flagged as a warning to alert the caller.
Why it happens
- 1Running an aggregate function such as SUM or AVG over a column that contains NULL values
How to reproduce
Aggregating a column with NULLs.
SELECT AVG(salary) FROM employees; -- some salary values are NULLFix 1: Use COALESCE to substitute NULLs before aggregating
When NULLs should be treated as zero or a default value in the aggregate.
SELECT AVG(COALESCE(salary, 0)) FROM employees;Why this works
COALESCE replaces NULLs before the aggregate sees them, preventing silent exclusion.
Fix 2: Filter NULLs explicitly with WHERE
When NULLs represent unknown data that should be excluded intentionally.
SELECT AVG(salary) FROM employees WHERE salary IS NOT NULL;Why this works
Making the exclusion explicit documents intent and suppresses the warning.
Sources
📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html
🔧 Source ref: Class 01 — Warning
Confidence assessment
✅ HIGH confidence
Standard SQL behaviour. Stable across all Postgres versions.
See also
🔗 Related errors
📄 Reference pages