Re: proposal - plpgsql - all plpgsql auto variables should be constant

From: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: proposal - plpgsql - all plpgsql auto variables should be constant
Date: 2020-04-24 11:36:33
Message-ID: CAExHW5tm9SsSMDEA4zEes2WUMJ7yjoEMhk=PevWfoFrTWAhSZg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Apr 24, 2020 at 12:24 PM Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
>
> Hi
>
> plpgsql generate lot of auto variables - FOUND, SQLERRM, cycle's control variable, TG_WHEN, TG_OP, ..
>
> Currently these variables are not protected, what can be source of problems, mainly for not experienced users. I propose mark these variables as constant.
>

+1 for general idea.

> -- today
> postgres=# do $$ begin for i in 1..10 loop raise notice 'i=%', i; i := 20; end loop; end; $$;
> NOTICE: i=1
> NOTICE: i=2
> NOTICE: i=3
> NOTICE: i=4
> NOTICE: i=5
> NOTICE: i=6
> NOTICE: i=7
> NOTICE: i=8
> NOTICE: i=9
> NOTICE: i=10
> DO
>
> -- after patch
> postgres=# do $$ begin for i in 1..10 loop raise notice 'i=%', i; i := 20; end loop; end; $$;
> ERROR: variable "i" is declared CONSTANT

CONSTANT looks odd in this context since i's value changes. But you
already have a proposal to change that.

>
> p.s. this is simple implementation - just for function demo. Maybe can be better to introduce new plpgsql_variable's flag like is_protected or similar than using isconst.

Yes, I think that will help. In this case PL/SQL says that "i" can not
be used as an assignment target. That's not very clear but something
on those lines will help.

--
Best Wishes,
Ashutosh Bapat

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2020-04-24 12:03:04 Re: Setting min/max TLS protocol in clientside libpq
Previous Message Peter Eisentraut 2020-04-24 10:56:31 Re: Setting min/max TLS protocol in clientside libpq