Re: PL/pgSQL 'i = i + 1' Syntax - Mailing list pgsql-hackers

From Mark Dilger
Subject Re: PL/pgSQL 'i = i + 1' Syntax
Date
Msg-id 446D0FE7.4090203@markdilger.com
Whole thread Raw
In response to Re: PL/pgSQL 'i = i + 1' Syntax  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: PL/pgSQL 'i = i + 1' Syntax
Re: PL/pgSQL 'i = i + 1' Syntax
List pgsql-hackers
Tom Lane wrote:
> Josh Berkus <josh@agliodbs.com> writes:
> 
>>>True, but there were clear benefits from doing so.  Disallowing "="
>>>assignment in plpgsql wouldn't buy anything, just break programs.
> 
> 
>>But it's already disallowed in most places.
> 
> 
> 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:

CREATE OR REPLACE FUNCTION foo () RETURNS INTEGER AS $$
DECLARE   i integer;
BEGIN   i := 1;   if i := 1 then       return 1;   end if;   return 0;
END;
$$ LANGUAGE plpgsql;


pgsql-hackers by date:

Previous
From: Mark Dilger
Date:
Subject: text_position worst case runtime
Next
From: Robert Treat
Date:
Subject: Re: [OT] MySQL is bad, but THIS bad?