PG
PRO
01003WARNINGTier 3 — Handle with care✅ HIGH confidence

null value eliminated in set function

Category: WarningVersions: All Postgres versions

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

  1. 1Running an aggregate function such as SUM or AVG over a column that contains NULL values

How to reproduce

Aggregating a column with NULLs.

trigger — this will ERROR
SELECT AVG(salary) FROM employees; -- some salary values are NULL
WARNING: null value eliminated in set function

Fix 1: Use COALESCE to substitute NULLs before aggregating

When NULLs should be treated as zero or a default value in the aggregate.

fix
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.

fix
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

📄 Reference pages

Aggregate FunctionsCOALESCE
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →