Re: plpgsql: can I use a variable in a DECLARE later whithin the DECLARE?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: tomas(at)tuxteam(dot)de
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: plpgsql: can I use a variable in a DECLARE later whithin the DECLARE?
Date: 2021-10-29 14:04:31
Message-ID: 626327.1635516271@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

<tomas(at)tuxteam(dot)de> writes:
> In plpgsql, i'm trying to use a variable initialised in a DECLARE in
> a later initialisation expression whithin the same DECLARE:

> DECLARE
> x int := 23;
> y int := x + 4
> BEGIN
> ...

> Experiments suggest that it works, but the docs are silent about that.
> Is this a good idea, or should I be more careful and do it in a nested
> block?

I don't see any reason to foresee that it would break.

However, I notice that we don't actually have any regression tests
checking this. scope_test() in plpgsql.sql checks an adjacent
question, but not exactly this one. I'm a bit inclined now to go
add such a test.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Daniel Gustafsson 2021-10-29 14:39:19 Re: Extension ownership and misuse of SET ROLE/SET SESSION AUTHORIZATION
Previous Message Hayk Manukyan 2021-10-29 13:32:37 Re: Feature request for adoptive indexes