IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
От:
jian he <jian.universality@gmail.com>
Дата:
Hi. While reviewing the row pattern recognition, I noticed that the IGNORE NULLS and RESPECT NULLS clauses can be specified for normal functions (prokind == 'f'). create or replace function dummy2(int) returns bigint AS $$ BEGIN RETURN $1; END$$ STABLE LANGUAGE plpgsql; select dummy2(1) IGNORE NULLS; select dummy2(1) RESPECT NULLS; This seems unexpected? Also https://git.postgresql.org/cgit/postgresql.git/commit/?id=25a30bbd4235a49c854036c84fe90f2bc5a87652 Obviously, RESPECT NULLS and IGNORE NULLS can appear in SELECT query, since they are dedicated keywords, shouldn't they be mentioned in select.sgml? -- jian https://www.enterprisedb.com/
Re: IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
От:
Tatsuo Ishii <ishii@postgresql.org>
Дата:
> While reviewing the row pattern recognition,
> I noticed that the IGNORE NULLS and RESPECT NULLS clauses can be specified for
> normal functions (prokind == 'f').
>
> create or replace function dummy2(int) returns bigint AS $$ BEGIN
> RETURN $1; END$$ STABLE LANGUAGE plpgsql;
> select dummy2(1) IGNORE NULLS;
> select dummy2(1) RESPECT NULLS;
>
> This seems unexpected?
Yes. Other than true window functions are not allowed to use the null
treatment clause per spec.
> Also https://git.postgresql.org/cgit/postgresql.git/commit/?id=25a30bbd4235a49c854036c84fe90f2bc5a87652
> Obviously, RESPECT NULLS and IGNORE NULLS can appear in SELECT query,
> since they are dedicated keywords, shouldn't they be mentioned in
> select.sgml?
No, we should fix the code. See attached patch.
To fix this, ParseFuncOrColumn() now checks whether other than window
functions are used with the null treatment clause. If so, error out.
Also remove the unnecessary test for "aggregate functions do not
accept RESPECT/IGNORE NULLS" because it is now checked in the
early-stage new check. The window regression test expected file is
changed accordingly.
Regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp
From 668f79937d19084ff93ea7b49810db443d2de148 Mon Sep 17 00:00:00 2001
From: Tatsuo Ishii
Date: Tue, 16 Jun 2026 20:51:59 +0900
Subject: [PATCH v1] Fix to not allow null treatment to non window functions.
The null treatment clause (RESPECT NULLS/IGNORE NULLS) are only
allowed to window functions per spec. Previously the check was only
applied to aggregates in window clause. Other type of functions were
allowed to use the clause, which was plain wrong.
To fix this, ParseFuncOrColumn() now checks whether other than window
functions are used with the null treatment clause. If so, error out.
Also remove the unnecessary test for "aggregate functions do not
accept RESPECT/IGNORE NULLS" because it is now checked in the
early-stage new check. The window regression test expected file is
changed accordingly.
Discussion: https://postgr.es/m/CACJufxFnm%2BAj2Jyhyd58PtW8e1vTZDKimkZE%2BMashCPSDKw56Q%40mail.gmail.com
---
src/backend/parser/parse_func.c | 16 +++++++++-------
src/test/regress/expected/window.out | 4 ++--
2 files changed, 11 insertions(+), 9 deletions(-)
diff --git a/src/backend/parser/parse_func.c b/src/backend/parser/parse_func.c
index 2e4cc1de50d..6717ddc6881 100644
--- a/src/backend/parser/parse_func.c
+++ b/src/backend/parser/parse_func.c
@@ -353,6 +353,15 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
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.
*/
@@ -519,13 +528,6 @@ ParseFuncOrColumn(ParseState *pstate, List *funcname, List *fargs,
errmsg("%s is not an ordered-set aggregate, so it cannot have WITHIN GROUP",
NameListToString(funcname)),
parser_errposition(pstate, location)));
-
- /* It also can't treat nulls as a window function */
- 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)
diff --git a/src/test/regress/expected/window.out b/src/test/regress/expected/window.out
index de0e14a686e..891b0153004 100644
--- a/src/test/regress/expected/window.out
+++ b/src/test/regress/expected/window.out
@@ -5764,11 +5764,11 @@ SELECT sum(orbit) OVER () FROM planets; -- succeeds
(10 rows)
SELECT sum(orbit) RESPECT NULLS OVER () FROM planets; -- fails
-ERROR: aggregate functions do not accept RESPECT/IGNORE NULLS
+ERROR: Only window functions accept RESPECT/IGNORE NULLS
LINE 1: SELECT sum(orbit) RESPECT NULLS OVER () FROM planets;
^
SELECT sum(orbit) IGNORE NULLS OVER () FROM planets; -- fails
-ERROR: aggregate functions do not accept RESPECT/IGNORE NULLS
+ERROR: Only window functions accept RESPECT/IGNORE NULLS
LINE 1: SELECT sum(orbit) IGNORE NULLS OVER () FROM planets;
^
SELECT row_number() OVER () FROM planets; -- succeeds
--
2.43.0
Re: IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
От:
Tatsuo Ishii <ishii@postgresql.org>
Дата:
>> > To fix this, ParseFuncOrColumn() now checks whether other than window >> > functions are used with the null treatment clause. If so, error out. >> > >> > Also remove the unnecessary test for "aggregate functions do not >> > accept RESPECT/IGNORE NULLS" because it is now checked in the >> > early-stage new check. The window regression test expected file is >> > changed accordingly. >> >> I'm going to push the patch today if there's no objection. > > The code looks good to me, and the commit message is clear and well-written. Thank you for the review! I have pushed the patch to master branch. https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=4e5920e6de87dc1ed761d2a898b7786c50c11db2 -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp
Re: IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
> On Jun 17, 2026, at 09:17, Tatsuo Ishii wrote: > >>>> To fix this, ParseFuncOrColumn() now checks whether other than window >>>> functions are used with the null treatment clause. If so, error out. >>>> >>>> Also remove the unnecessary test for "aggregate functions do not >>>> accept RESPECT/IGNORE NULLS" because it is now checked in the >>>> early-stage new check. The window regression test expected file is >>>> changed accordingly. >>> >>> I'm going to push the patch today if there's no objection. >> >> The code looks good to me, and the commit message is clear and well-written. > > Thank you for the review! > I have pushed the patch to master branch. > https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=4e5920e6de87dc1ed761d2a898b7786c50c11db2 > -- > Tatsuo Ishii > SRA OSS K.K. > English: http://www.sraoss.co.jp/index_en/ > Japanese:http://www.sraoss.co.jp > Hi Tatsuo-san, Sorry for jumping in. I didn’t review the patch, but while browsing recent commits, I noticed that this commit has a small issue: the errmsg should start with a lowercase character, according to the error style guide [1]: ``` Primary error messages: Do not capitalize the first letter. Do not end a message with a period. Do not even think about ending a message with an exclamation point. ``` The attached diff is a quick fix that changes “Only” to “only” and updates the expected output accordingly. [1] https://www.postgresql.org/docs/current/error-style-guide.html Best regards, -- Chao Li (Evan) HighGo Software Co., Ltd. https://www.highgo.com/
Re: IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
От:
Tatsuo Ishii <ishii@postgresql.org>
Дата:
Hi Chao, > Hi Tatsuo-san, > > Sorry for jumping in. I didn’t review the patch, but while browsing recent commits, I noticed that this commit has a small issue: the errmsg should start with a lowercase character, according to the error style guide [1]: > ``` > Primary error messages: Do not capitalize the first letter. Do not end a message with a period. Do not even think about ending a message with an exclamation point. > ``` > > The attached diff is a quick fix that changes “Only” to “only” and updates the expected output accordingly. > > [1] https://www.postgresql.org/docs/current/error-style-guide.html You are right. I don't know why I forgot the rule. Patch pushed. Thank you! -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp
Re: IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
On Wed, Jun 17, 2026 at 12:58 PM Tatsuo Ishii wrote:
>
> Hi Chao,
>
> > Hi Tatsuo-san,
> >
> > Sorry for jumping in. I didn’t review the patch, but while browsing recent commits, I noticed that this commit has a small issue: the errmsg should start with a lowercase character, according to the error style guide [1]:
> > ```
> > Primary error messages: Do not capitalize the first letter. Do not end a message with a period. Do not even think about ending a message with an exclamation point.
> > ```
> >
> > The attached diff is a quick fix that changes “Only” to “only” and updates the expected output accordingly.
> >
> > [1] https://www.postgresql.org/docs/current/error-style-guide.html
>
> You are right. I don't know why I forgot the rule. Patch pushed.
> Thank you!
Thanks for working on this!
I have a couple of comments.
When executing a non-existent function with IGNORE NULLS, for example,
SELECT no_such_func() IGNORE NULLS;
previously we got:
ERROR: function no_such_func() does not exist
but now we get:
ERROR: only window functions accept RESPECT/IGNORE NULLS
Isn't the previous error more helpful in this case? It makes me wonder
whether the IGNORE NULLS check is being performed too early. Perhaps
it would be better to move the check to other place.
I also noticed that when using an aggregate function as a window
function, for example,
SELECT sum(i) IGNORE NULLS OVER() FROM ...;
we now get:
ERROR: only window functions accept RESPECT/IGNORE NULLS
whereas previously the error was:
ERROR: aggregate functions do not accept RESPECT/IGNORE NULLS
The new message seems confusing because `sum()` is being used as
a window function in this case, so saying "only window functions accept ..."
doesn't seem accurate.
/*
* NULL TREATEMENT is only allowed for window functions per spec.
*/
Also, I noticed a typo: TREATEMENT should be TREATMENT.
The attached patch implements these changes. Thoughts?
Regards,
--
Fujii Masao
Re: IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
От:
Tatsuo Ishii <ishii@postgresql.org>
Дата:
Hi,
> Thanks for working on this!
>
> I have a couple of comments.
>
> When executing a non-existent function with IGNORE NULLS, for example,
>
> SELECT no_such_func() IGNORE NULLS;
>
> previously we got:
>
> ERROR: function no_such_func() does not exist
>
> but now we get:
>
> ERROR: only window functions accept RESPECT/IGNORE NULLS
>
> Isn't the previous error more helpful in this case? It makes me wonder
> whether the IGNORE NULLS check is being performed too early. Perhaps
> it would be better to move the check to other place.
Agreed. BTW, if the check is moved there, it might be better to
change the error message according to the surroundings. The pattern is
"... specified, but %s is not a ..."
errmsg("OVER specified, but %s is not a window function nor an aggregate function",
So the message could be changed to something like:
errmsg("RESPECT/IGNORE NULLS is specified, but %s is not a window function"),
> I also noticed that when using an aggregate function as a window
> function, for example,
>
> SELECT sum(i) IGNORE NULLS OVER() FROM ...;
>
> we now get:
>
> ERROR: only window functions accept RESPECT/IGNORE NULLS
>
> whereas previously the error was:
>
> ERROR: aggregate functions do not accept RESPECT/IGNORE NULLS
>
> The new message seems confusing because `sum()` is being used as
> a window function in this case, so saying "only window functions accept ..."
> doesn't seem accurate.
I agree with your concern and am fine with the change.
> /*
> * NULL TREATEMENT is only allowed for window functions per spec.
> */
>
> Also, I noticed a typo: TREATEMENT should be TREATMENT.
Thanks for the correction.
>
> The attached patch implements these changes. Thoughts?
Please see comment above.
Regards,
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp
Re: IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
От:
Chao Li <li.evan.chao@gmail.com>
Дата:
> On Jun 18, 2026, at 10:44, Tatsuo Ishii wrote:
>
> Hi,
>
>> Thanks for working on this!
>>
>> I have a couple of comments.
>>
>> When executing a non-existent function with IGNORE NULLS, for example,
>>
>> SELECT no_such_func() IGNORE NULLS;
>>
>> previously we got:
>>
>> ERROR: function no_such_func() does not exist
>>
>> but now we get:
>>
>> ERROR: only window functions accept RESPECT/IGNORE NULLS
>>
>> Isn't the previous error more helpful in this case? It makes me wonder
>> whether the IGNORE NULLS check is being performed too early. Perhaps
>> it would be better to move the check to other place.
>
> Agreed. BTW, if the check is moved there, it might be better to
> change the error message according to the surroundings. The pattern is
> "... specified, but %s is not a ..."
>
> errmsg("OVER specified, but %s is not a window function nor an aggregate function",
>
> So the message could be changed to something like:
>
> errmsg("RESPECT/IGNORE NULLS is specified, but %s is not a window function"),
>
Yes, this is also my only comment for the patch.
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
Re: IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
От:
Tatsuo Ishii <ishii@postgresql.org>
Дата:
> I've updated the patch accordingly. > > I removed "is" from "RESPECT/IGNORE NULLS is specified" to match other > similar error messages, which use the form "XXX specified, ...". > > + if (ignore_nulls != NO_NULLTREATMENT) > + ereport(ERROR, > + (errcode(ERRCODE_WRONG_OBJECT_TYPE), The errcode field can start without a parenthesis: errcode(ERRCODE_WRONG_OBJECT_TYPE), Other than that the patch looks good to me. Regards, -- Tatsuo Ishii SRA OSS K.K. English: http://www.sraoss.co.jp/index_en/ Japanese:http://www.sraoss.co.jp
Re: IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
От:
Álvaro Herrera <alvherre@kurilemu.de>
Дата:
Hello,
I would dearly appreciate it if you could make these errors in this
style:
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
/* translator: first %s is a CREATE FUNCTION clause, eg. "IGNORE NULLS" */
errmsg("%s specified, but %s is not a window function",
"RESPECT/IGNORE NULLS", NameListToString(funcname)),
parser_errposition(pstate, location)));
to avoid keeping the clause name in the translatable string.
Thanks
--
Álvaro Herrera Breisgau, Deutschland — https://www.EnterpriseDB.com/
"Entristecido, Wutra (canción de Las Barreras)
echa a Freyr a rodar
y a nosotros al mar"
Re: IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
On Thu, Jun 18, 2026 at 11:46 PM Álvaro Herrera wrote:
>
> Hello,
>
> I would dearly appreciate it if you could make these errors in this
> style:
>
> ereport(ERROR,
> (errcode(ERRCODE_WRONG_OBJECT_TYPE),
> /* translator: first %s is a CREATE FUNCTION clause, eg. "IGNORE NULLS" */
> errmsg("%s specified, but %s is not a window function",
> "RESPECT/IGNORE NULLS", NameListToString(funcname)),
> parser_errposition(pstate, location)));
>
> to avoid keeping the clause name in the translatable string.
Thanks for the suggestion! I've updated the patch accordingly.
Patch attached.
Regards,
--
Fujii Masao
Re: IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Thu, Jun 18, 2026 at 5:28 PM Tatsuo Ishii wrote: > > > I've updated the patch accordingly. > > > > I removed "is" from "RESPECT/IGNORE NULLS is specified" to match other > > similar error messages, which use the form "XXX specified, ...". > > > > + if (ignore_nulls != NO_NULLTREATMENT) > > + ereport(ERROR, > > + (errcode(ERRCODE_WRONG_OBJECT_TYPE), > > The errcode field can start without a parenthesis: > > errcode(ERRCODE_WRONG_OBJECT_TYPE), Yes, but other similar ereport() calls in parse_func.c also start the errcode field with a parenthesis, so I followed the same style here. Regards, -- Fujii Masao
Re: IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Fri, Jun 19, 2026 at 1:12 AM Fujii Masao wrote:
>
> On Thu, Jun 18, 2026 at 11:46 PM Álvaro Herrera wrote:
> >
> > Hello,
> >
> > I would dearly appreciate it if you could make these errors in this
> > style:
> >
> > ereport(ERROR,
> > (errcode(ERRCODE_WRONG_OBJECT_TYPE),
> > /* translator: first %s is a CREATE FUNCTION clause, eg. "IGNORE NULLS" */
> > errmsg("%s specified, but %s is not a window function",
> > "RESPECT/IGNORE NULLS", NameListToString(funcname)),
> > parser_errposition(pstate, location)));
> >
> > to avoid keeping the clause name in the translatable string.
>
> Thanks for the suggestion! I've updated the patch accordingly.
> Patch attached.
Barring any objections, I will commit the patch.
Regards,
--
Fujii Masao
Re: IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
От:
Tatsuo Ishii <ishii@postgresql.org>
Дата:
> On Fri, Jun 19, 2026 at 1:12 AM Fujii Masao wrote:
>>
>> On Thu, Jun 18, 2026 at 11:46 PM Álvaro Herrera wrote:
>> >
>> > Hello,
>> >
>> > I would dearly appreciate it if you could make these errors in this
>> > style:
>> >
>> > ereport(ERROR,
>> > (errcode(ERRCODE_WRONG_OBJECT_TYPE),
>> > /* translator: first %s is a CREATE FUNCTION clause, eg. "IGNORE NULLS" */
>> > errmsg("%s specified, but %s is not a window function",
>> > "RESPECT/IGNORE NULLS", NameListToString(funcname)),
>> > parser_errposition(pstate, location)));
>> >
>> > to avoid keeping the clause name in the translatable string.
>>
>> Thanks for the suggestion! I've updated the patch accordingly.
>> Patch attached.
>
> Barring any objections, I will commit the patch.
No objection from me.
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp
Re: IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
Hi Fujii-san,
I've pushed the patch. Thanks!
While reading ParseFuncOrColumn(), I noticed that commit 419ce13b701
left a stray blank line just before the closing brace of the
normal-aggregate block in the FUNCDETAIL_AGGREGATE arm (right before
the new "aggregate functions do not accept RESPECT/IGNORE NULLS"
check).
Trivial cleanup attached; no functional change.
Regards,
Henson Choi
left a stray blank line just before the closing brace of the
normal-aggregate block in the FUNCDETAIL_AGGREGATE arm (right before
the new "aggregate functions do not accept RESPECT/IGNORE NULLS"
check).
Trivial cleanup attached; no functional change.
Regards,
Henson Choi
Re: IGNORE/RESPECT NULLS can be specified for (prokind == 'f').
От:
Fujii Masao <masao.fujii@gmail.com>
Дата:
On Thu, Jun 25, 2026 at 11:15 PM Henson Choi wrote: > > Hi Fujii-san, > >> I've pushed the patch. Thanks! > > > While reading ParseFuncOrColumn(), I noticed that commit 419ce13b701 > left a stray blank line just before the closing brace of the > normal-aggregate block in the FUNCDETAIL_AGGREGATE arm (right before > the new "aggregate functions do not accept RESPECT/IGNORE NULLS" > check). > > Trivial cleanup attached; no functional change. Thanks for the patch! I've pushed it. Regards, -- Fujii Masao