pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: tomas@tuxteam.de
To: Tom Lane <tgl@sss.pgh.pa.us>
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 16:50:30 +0200
Message-ID: <20211029145030.GA13799@tuxteam.de> (raw)
In-Reply-To: <626327.1635516271@sss.pgh.pa.us>
References: <20211029121435.GA5414@tuxteam.de>
	<626327.1635516271@sss.pgh.pa.us>

On Fri, Oct 29, 2021 at 10:04:31AM -0400, Tom Lane wrote:
> <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.

Thanks :)

> 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.

Even more thanks.

After a long hiatus I have the luck to play again with PostgreSQL.
Let me say: you folks rock, seriously.

Cheers
 - t

Attachments:

  signature.asc (application/pgp-signature, 197B) download

view thread (3+ messages)

Message-ID: <20211029145030.GA13799@tuxteam.de>
Permalink:  ../20211029145030.GA13799@tuxteam.de/
Also on:    postgresql.org/message-id/20211029145030.GA13799@tuxteam.de

 · 

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: tomas@tuxteam.de, tgl@sss.pgh.pa.us
  Subject: Re: plpgsql: can I use a variable in a DECLARE later whithin the DECLARE?
  In-Reply-To: <20211029145030.GA13799@tuxteam.de>
  References: <20211029121435.GA5414@tuxteam.de> <626327.1635516271@sss.pgh.pa.us> <20211029145030.GA13799@tuxteam.de>

* 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