pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: tomas@tuxteam.de
Cc: pgsql-hackers@postgresql.org
Subject: Re: plpgsql: can I use a variable in a DECLARE later whithin the DECLARE?
Date: Fri, 29 Oct 2021 10:04:31 -0400
Message-ID: <626327.1635516271@sss.pgh.pa.us> (raw)
In-Reply-To: <20211029121435.GA5414@tuxteam.de>
References: <20211029121435.GA5414@tuxteam.de>

<tomas@tuxteam.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





view thread (3+ messages)  latest in thread

Message-ID: <626327.1635516271@sss.pgh.pa.us>
Permalink:  ../626327.1635516271@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/626327.1635516271@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, tomas@tuxteam.de
  Subject: Re: plpgsql: can I use a variable in a DECLARE later whithin the DECLARE?
  In-Reply-To: <626327.1635516271@sss.pgh.pa.us>
  References: <20211029121435.GA5414@tuxteam.de> <626327.1635516271@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox