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

From: Mark Dilger <pgsql(at)markdilger(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Subject: Re: PL/pgSQL 'i = i + 1' Syntax
Date: 2006-05-19 00:23:03
Message-ID: 446D0FE7.4090203@markdilger.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> Josh Berkus <josh(at)agliodbs(dot)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;

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Treat 2006-05-19 00:35:02 Re: [OT] MySQL is bad, but THIS bad?
Previous Message Mark Dilger 2006-05-19 00:17:19 text_position worst case runtime