proposal - plpgsql - all plpgsql auto variables should be constant

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: proposal - plpgsql - all plpgsql auto variables should be constant
Date: 2020-04-24 06:53:45
Message-ID: CAFj8pRBu_qZ72OhTQeh2nM3Mm_9oMpECm08Tgj1Ks0dd=n2ggw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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.

-- 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
LINE 1: ... begin for i in 1..10 loop raise notice 'i=%', i; i := 20; e...

These variables are protected in PL/SQL too.

Comments, notes?

Regards

Pavel

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.

Attachment Content-Type Size
plpgsql-make-auto-const.patch text/x-patch 8.2 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2020-04-24 07:05:10 Re: [BUG] non archived WAL removed during production crash recovery
Previous Message Kyotaro Horiguchi 2020-04-24 06:36:51 Re: 2pc leaks fds