errmsg("OVER specified, but %s is not a window function nor an aggregate function",
NameListToString(funcname)),
parser_errposition(pstate, location)));
+ if (ignore_nulls != NO_NULLTREATMENT)
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ /*- translator: first %s is a null treatment option, eg IGNORE NULLS */
+ errmsg("%s specified, but %s is not a window function",
+ "RESPECT/IGNORE NULLS", NameListToString(funcname)),
+ parser_errposition(pstate, location)));
}
- /*
- * NULL TREATEMENT is only allowed for window functions per spec.
- */
- if (fdresult != FUNCDETAIL_WINDOWFUNC && ignore_nulls != NO_NULLTREATMENT)
- ereport(ERROR,
- errcode(ERRCODE_WRONG_OBJECT_TYPE),
- errmsg("only window functions accept RESPECT/IGNORE NULLS"),
- parser_errposition(pstate, location));
-
/*
* So far so good, so do some fdresult-type-specific processing.
*/
errmsg("%s is not an ordered-set aggregate, so it cannot have WITHIN GROUP",
NameListToString(funcname)),
parser_errposition(pstate, location)));
+
}
+
+ if (ignore_nulls != NO_NULLTREATMENT)
+ ereport(ERROR,
+ (errcode(ERRCODE_WRONG_OBJECT_TYPE),
+ errmsg("aggregate functions do not accept RESPECT/IGNORE NULLS"),
+ parser_errposition(pstate, location)));
}
else if (fdresult == FUNCDETAIL_WINDOWFUNC)
{
(10 rows)
-- valid and invalid functions
+SELECT abs(1) IGNORE NULLS; -- fails
+ERROR: RESPECT/IGNORE NULLS specified, but abs is not a window function
+LINE 1: SELECT abs(1) IGNORE NULLS;
+ ^
+SELECT no_such_window_func() IGNORE NULLS; -- fails, but not because of null treatment
+ERROR: function no_such_window_func() does not exist
+LINE 1: SELECT no_such_window_func() IGNORE NULLS;
+ ^
+DETAIL: There is no function of that name.
+SELECT sum(orbit) IGNORE NULLS FROM planets; -- fails
+ERROR: aggregate functions do not accept RESPECT/IGNORE NULLS
+LINE 1: SELECT sum(orbit) IGNORE NULLS FROM planets;
+ ^
SELECT sum(orbit) OVER () FROM planets; -- succeeds
sum
--------
(10 rows)
SELECT sum(orbit) RESPECT NULLS OVER () FROM planets; -- fails
-ERROR: only window functions accept RESPECT/IGNORE NULLS
+ERROR: aggregate functions do not accept RESPECT/IGNORE NULLS
LINE 1: SELECT sum(orbit) RESPECT NULLS OVER () FROM planets;
^
SELECT sum(orbit) IGNORE NULLS OVER () FROM planets; -- fails
-ERROR: only window functions accept RESPECT/IGNORE NULLS
+ERROR: aggregate functions do not accept RESPECT/IGNORE NULLS
LINE 1: SELECT sum(orbit) IGNORE NULLS OVER () FROM planets;
^
SELECT row_number() OVER () FROM planets; -- succeeds
;
-- valid and invalid functions
+SELECT abs(1) IGNORE NULLS; -- fails
+SELECT no_such_window_func() IGNORE NULLS; -- fails, but not because of null treatment
+SELECT sum(orbit) IGNORE NULLS FROM planets; -- fails
SELECT sum(orbit) OVER () FROM planets; -- succeeds
SELECT sum(orbit) RESPECT NULLS OVER () FROM planets; -- fails
SELECT sum(orbit) IGNORE NULLS OVER () FROM planets; -- fails