Skip site navigation (1) Skip section navigation (2)

Precedence of Postfix operators

From: Gokulakannan Somasundaram <gokul007(at)gmail(dot)com>
To: pgsql-hackers list <pgsql-hackers(at)postgresql(dot)org>
Subject: Precedence of Postfix operators
Date: 2010-02-07 12:07:20
Message-ID: 9362e74e1002070407x1eddacd4sfc0e8938b7e4ba4f@mail.gmail.com (view raw)
Hi,
   Is there any reason why we have given lesser precedence for postfix
operator compared to multiplication/division? Usually postfix operators have
more precedence than the binary operations. Is this some kind of work around
to provide user-defined operators? Can someone help me understand this?

Thanks,
Gokul.
From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Gokulakannan Somasundaram <gokul007(at)gmail(dot)com>
Cc: pgsql-hackers list <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Precedence of Postfix operators
Date: 2010-02-07 16:44:38
Message-ID: 24430.1265561078@sss.pgh.pa.us (view raw)
Gokulakannan Somasundaram <gokul007(at)gmail(dot)com> writes:
>    Is there any reason why we have given lesser precedence for postfix
> operator compared to multiplication/division? Usually postfix operators have
> more precedence than the binary operations. Is this some kind of work around
> to provide user-defined operators? Can someone help me understand this?

A bit of poking in the CVS logs for gram.y reveals

2001-01-23 17:39  tgl

	* src/backend/parser/gram.y: Give 'a_expr ::= a_expr Op' production
	a slightly lower precedence than Op, so that the sequence 'a_expr
	Op Op a_expr' will be parsed as a_expr Op (Op a_expr) not (a_expr
	Op) Op a_expr as formerly.  In other words, prefer treating
	user-defined operators as prefix operators to treating them as
	postfix operators, when there is an ambiguity.	Also clean up a
	couple of other infelicities in production priority assignment ---
	for example, BETWEEN wasn't being given the intended priority, but
	that of AND.

There are several other nasty things that we've had to do in order to
keep supporting postfix operators at all.  I thibk most people view them
as a legacy feature best avoided.

			regards, tom lane

From: Gokulakannan Somasundaram <gokul007(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers list <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Precedence of Postfix operators
Date: 2010-02-07 22:22:26
Message-ID: 9362e74e1002071422h6c66fe92mb98bd81c8b4e23d5@mail.gmail.com (view raw)
Thanks Tom, for the explanation.

Gokul.

On Sun, Feb 7, 2010 at 10:14 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Gokulakannan Somasundaram <gokul007(at)gmail(dot)com> writes:
> >    Is there any reason why we have given lesser precedence for postfix
> > operator compared to multiplication/division? Usually postfix operators
> have
> > more precedence than the binary operations. Is this some kind of work
> around
> > to provide user-defined operators? Can someone help me understand this?
>
> A bit of poking in the CVS logs for gram.y reveals
>
> 2001-01-23 17:39  tgl
>
>        * src/backend/parser/gram.y: Give 'a_expr ::= a_expr Op' production
>        a slightly lower precedence than Op, so that the sequence 'a_expr
>        Op Op a_expr' will be parsed as a_expr Op (Op a_expr) not (a_expr
>        Op) Op a_expr as formerly.  In other words, prefer treating
>        user-defined operators as prefix operators to treating them as
>        postfix operators, when there is an ambiguity.  Also clean up a
>        couple of other infelicities in production priority assignment ---
>        for example, BETWEEN wasn't being given the intended priority, but
>        that of AND.
>
> There are several other nasty things that we've had to do in order to
> keep supporting postfix operators at all.  I thibk most people view them
> as a legacy feature best avoided.
>
>                        regards, tom lane
>

Privacy Policy | About PostgreSQL
Copyright © 1996-2013 The PostgreSQL Global Development Group