Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g4emH-0004HX-3w for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Sep 2018 04:16:49 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g4emE-00012p-7N for pgsql-hackers@arkaria.postgresql.org; Tue, 25 Sep 2018 04:16:46 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g4emD-00012i-Lh for pgsql-hackers@lists.postgresql.org; Tue, 25 Sep 2018 04:16:45 +0000 Received: from lungold.riddles.org.uk ([82.68.208.19]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g4em5-0007A9-Iu for pgsql-hackers@postgresql.org; Tue, 25 Sep 2018 04:16:44 +0000 Received: from [192.168.127.1] (port=12435 helo=caithnard.riddles.org.uk) by lungold.riddles.org.uk with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.88 (FreeBSD)) (envelope-from ) id 1g4elx-000Els-Dw; Tue, 25 Sep 2018 04:16:29 +0000 Received: from [127.0.0.1] (port=36659 helo=caithnard.riddles.org.uk) by caithnard.riddles.org.uk with esmtp (Exim 4.89 (FreeBSD)) (envelope-from ) id 1g4elw-000498-OY; Tue, 25 Sep 2018 04:16:28 +0000 From: Andrew Gierth To: Tom Lane Cc: pgsql-hackers@postgresql.org, david@fetter.org, Oliver Ford , Krasiyan Andreev Subject: Re: Add RESPECT/IGNORE NULLS and FROM FIRST/LAST options In-Reply-To: <9361.1537744225@sss.pgh.pa.us> (Tom Lane's message of "Sun, 23 Sep 2018 19:10:25 -0400") Message-ID: <8736tygr5e.fsf@news-spur.riddles.org.uk> References: <20180728185958.GP17411@fetter.org> <878t3vj279.fsf@news-spur.riddles.org.uk> <2897.1537737232@sss.pgh.pa.us> <87va6vhoey.fsf@news-spur.riddles.org.uk> <9361.1537744225@sss.pgh.pa.us> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.1 (berkeley-unix) Date: Tue, 25 Sep 2018 05:16:27 +0100 MIME-Version: 1.0 Content-Type: text/plain List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk So I've tried to rough out a decision tree for the various options on how this might be implemented (discarding the "use precedence hacks" option). Opinions? Additions? (formatted for emacs outline-mode) * 1. use lexical lookahead +: relatively straightforward parser changes +: no new reserved words +: has the option of working extensibly with all functions -: base_yylex needs extending to 3 lookahead tokens ** 1.1. Allow from/ignore clause on all (or all non-agg) window function calls If the clauses are legal on all window functions, what to do about existing window functions for which the clauses do not make sense? *** 1.1.1. Ignore the clause when the function isn't aware of it +: simple -: somewhat surprising for users perhaps? *** 1.1.2. Change the behavior of the windowapi in some consistent way Not sure if this can work. +: fairly simple(maybe?) and predictable -: changes the behavior of existing window functions ** 1.2. Allow from/ignore clause on only certain functions +: avoids any unexpected behavior -: needs some way to control what functions allow it *** 1.2.1. Check the function name in parse analysis against a fixed list. +: simple -: not extensible *** 1.2.2. Provide some option in CREATE FUNCTION +: extensible -: fairly intrusive, adding stuff to create function and pg_proc *** 1.2.3. Do something magical with function argument types +: doesn't need changes in create function / pg_proc -: it's an ugly hack * 2. reserve nth_value etc. as functions +: follows the spec reasonably well +: less of a hack than extending base_yylex -: new reserved words -: more parser rules -: not extensible (now goto 1.2.1) * 3. "just say no" to the spec e.g. add new functions like lead_ignore_nulls(), or add extra boolean args to lead() etc. telling them to skip nulls +: simple -: doesn't conform to spec -: using extra args isn't quite the right semantics -- Andrew (irc:RhodiumToad)