Re: PL/pgSQL 'i = i + 1' Syntax

From: "Jim C(dot) Nasby" <jnasby(at)pervasive(dot)com>
To: Douglas McNaught <doug(at)mcnaught(dot)org>
Cc: Mark Dilger <pgsql(at)markdilger(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: PL/pgSQL 'i = i + 1' Syntax
Date: 2006-05-19 16:24:36
Message-ID: 20060519162436.GA64371@pervasive.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, May 18, 2006 at 08:40:04PM -0400, Douglas McNaught wrote:
> Mark Dilger <pgsql(at)markdilger(dot)com> writes:
>
> > Tom Lane wrote:
> >> No it isn't. The plpgsql scanner treats := and = as *the same token*.
> >> They can be interchanged freely. This has nothing to do with the case
> >> of modifying a loop variable in particular.
> >
> > I disagree. If the scanner treated them the same, then
> >
> > if i := 1 then ...
> >
> > would work, but it doesn't. The := is rejected in a conditional. Try the
> > following code if you don't believe me:
>
> That's because (AIUI) all expressions to be evaluated are handed off
> to the SQL parser (why re-implement all that logic and have subtle and
> annoying differences?) plpgsql only handles the statements, loops, etc.
> So it doesn't care about the difference but SQL does...

Something that's always bugged me is how horribly variables are handled
in plpgsql, namely that if you have a variable and a field with the same
name it can be extremely difficult to keep them seperated. Perhaps := vs
= might be a way to keep it clear as to which is which...

Though, a better way would probably just be to provide a built-in
construct for referencing plpgsql variables, such as $.
--
Jim C. Nasby, Sr. Engineering Consultant jnasby(at)pervasive(dot)com
Pervasive Software http://pervasive.com work: 512-231-6117
vcard: http://jim.nasby.net/pervasive.vcf cell: 512-569-9461

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Simon Riggs 2006-05-19 16:25:31 Re: does wal archiving block the current client connection?
Previous Message Andrew Dunstan 2006-05-19 16:22:25 Re: [OT] MySQL is bad, but THIS bad?