Re: factorial function/phase out postfix operators?

Vik Fearing <vik@postgresfriends.org>

From: Vik Fearing <vik@postgresfriends.org>
To: Robert Haas <robertmhaas@gmail.com>, Tom Lane <tgl@sss.pgh.pa.us>
Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>, pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2020-05-19T14:36:13Z
Lists: pgsql-hackers
On 5/19/20 4:22 PM, Robert Haas wrote:
> On Tue, May 19, 2020 at 9:51 AM Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> Uh ... what exactly would be the point of that?  The real reason to do
>> this at all is not that we have it in for '!', but that we want to
>> drop the possibility of postfix operators from the grammar altogether,
>> which will remove a boatload of ambiguity.
> 
> The ambiguity doesn't come from the mere existence of postfix
> operators. It comes from the fact that, when we lex the input, we
> can't tell whether a particular operator that we happen to encounter
> is prefix, infix, or postfix. So hard-coding, for example, a rule that
> '!' is always a postfix operator and anything else is never a postfix
> operator is sufficient to solve the key problems. Then "SELECT a ! b"
> can only be a postfix operator application followed by a column
> labeling, a "SELECT a + b" can only be the application of an infix
> operator.

So if I make a complex UDT where a NOT operator makes a lot of sense[*],
why wouldn't I be allowed to make a prefix operator ! for it?  All for
what?  That one person in the corner over there who doesn't want to
rewrite their query to use factorial() instead?

I'm -1 on keeping ! around as a hard-coded postfix operator.


[*] I don't have a concrete example in mind, just this abstract one.
-- 
Vik Fearing



Commits

  1. Remove precedence hacks no longer needed without postfix operators.

  2. Allow most keywords to be used as column labels without requiring AS.

  3. Remove support for postfix (right-unary) operators.

  4. Remove factorial operators, leaving only the factorial() function.

  5. Further refine patch for commenting operator implementation functions.