[PATCH] Add regression test for aggregate NULL behavior
Hi,
This patch adds a new regression test covering the behavior of aggregate
functions when handling NULL values, including COUNT, COUNT(*) and AVG
on non-empty and empty relations.
The test was implemented using the pg_regress framework and follows the
existing regression testing conventions.
Feedback is welcome.
Best regards,
Kateriny
Attachments:
aggregate_null_behavior.patchapplication/octet-stream; name=aggregate_null_behavior.patchDownload
diff --git a/src/test/regress/expected/aggregate_null_behavior.out b/src/test/regress/expected/aggregate_null_behavior.out
new file mode 100644
index 00000000000..6f0fb9b26f3
--- /dev/null
+++ b/src/test/regress/expected/aggregate_null_behavior.out
@@ -0,0 +1,19 @@
+ count
+-------
+ 2
+(1 row)
+
+ count
+-------
+ 3
+(1 row)
+
+ avg
+--------------------
+ 1.5000000000000000
+(1 row)
+
+ avg
+-----
+
+(1 row)
diff --git a/src/test/regress/parallel_schedule b/src/test/regress/parallel_schedule
index 905f9bca959..efd462eea17 100644
--- a/src/test/regress/parallel_schedule
+++ b/src/test/regress/parallel_schedule
@@ -43,7 +43,7 @@ test: copy copyselect copydml copyencoding insert insert_conflict
# Note: many of the tests in later groups depend on create_index
# ----------
test: create_function_c create_misc create_operator create_procedure create_table create_type create_schema
-test: create_index create_index_spgist create_view index_including index_including_gist
+
# ----------
# Another group of parallel tests
@@ -140,3 +140,7 @@ test: fast_default
# run tablespace test at the end because it drops the tablespace created during
# setup that other tests may use.
test: tablespace
+# ----------
+# Aggregate NULL behavior tests
+# ----------
+test: aggregate_null_behavior
diff --git a/src/test/regress/sql/aggregate_null_behavior.sql b/src/test/regress/sql/aggregate_null_behavior.sql
new file mode 100644
index 00000000000..e76891d9f12
--- /dev/null
+++ b/src/test/regress/sql/aggregate_null_behavior.sql
@@ -0,0 +1,11 @@
+CREATE TEMP TABLE t (x INT);
+
+INSERT INTO t VALUES (1), (NULL), (2);
+
+SELECT COUNT(x) FROM t;
+SELECT COUNT(*) FROM t;
+SELECT AVG(x) FROM t;
+
+DELETE FROM t;
+SELECT AVG(x) FROM t;
+
Hi Kateriny,
On Tue, Dec 16, 2025 at 6:21 PM kateriny bispo
<katerinybispo06@gmail.com> wrote:
Hi,
This patch adds a new regression test covering the behavior of aggregate
functions when handling NULL values, including COUNT, COUNT(*) and AVG
on non-empty and empty relations.The test was implemented using the pg_regress framework and follows the
existing regression testing conventions.Feedback is welcome.
These tests should go to aggregates.sql. That file already has some
tests for NULL input to aggregates. Do those cover the cases you want
to cover?
--
Best Wishes,
Ashutosh Bapat