An empty alarm-threshold lookup errors globally but returns NULL when correlated
02:53 30 Oct 2026

This is the smallest alarm-threshold lookup I can reproduce:

CREATE DATABASE alarm_thresholds;
USE alarm_thresholds;
CREATE TABLE limits(station STRING TAG, threshold INT32 FIELD);
INSERT INTO limits(time,station,threshold) VALUES (1000,'west',80);

An absent threshold should be distinguishable from a failed lookup. On Apache IoTDB 2.0.10, table model, using CLI 2.0.10, the non-correlated lookup below throws even though it cannot return more than one row:

SELECT station,(SELECT threshold FROM limits WHERE threshold<0) AS missing FROM limits ORDER BY time;

Msg: org.apache.iotdb.jdbc.IoTDBSQLException: 701: Scalar sub-query does not have output.

Adding a correlation on the only station in this dataset returns NULL instead:

SELECT station,(SELECT s.threshold FROM limits s WHERE s.station=r.station AND s.threshold<0) AS missing FROM limits r ORDER BY time;
+-------+-------+
|station|missing|
+-------+-------+
|   west|   null|
+-------+-------+

An aggregate over the same empty input also returns NULL:

SELECT station,(SELECT MAX(threshold) FROM limits WHERE threshold<0) AS missing FROM limits ORDER BY time;
+-------+-------+
|station|missing|
+-------+-------+
|   west|   null|
+-------+-------+

For comparison, the non-correlated form works when its inner query has one row:

SELECT station,(SELECT threshold FROM limits WHERE threshold=80) AS missing FROM limits ORDER BY time;
+-------+-------+
|station|missing|
+-------+-------+
|   west|     80|
+-------+-------+

I expected the first lookup to return west, NULL, matching the correlated lookup on this one-station dataset. No query above produces multiple matching threshold rows.

Why does the zero-row result become an error only for the non-correlated scalar lookup in this version?

sql subquery apache-iotdb