1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-30 11:03:19 +03:00

Test and document the behavior of initialization cross-refs in plpgsql.

We had a test showing that a variable isn't referenceable in its
own initialization expression, nor in prior ones in the same block.
It *is* referenceable in later expressions in the same block, but
AFAICS there is no test case exercising that.  Add one, and also
add some error cases.

Also, document that this is possible, since the docs failed to
cover the point.

Per question from tomás at tuxteam.  I don't feel any need to
back-patch this, but we should ensure we don't break it in future.

Discussion: https://postgr.es/m/20211029121435.GA5414@tuxteam.de
This commit is contained in:
Tom Lane
2021-10-29 12:45:33 -04:00
parent 937aafd6d5
commit a2a731d6c9
3 changed files with 76 additions and 20 deletions

View File

@ -379,7 +379,17 @@ arow RECORD;
<programlisting>
quantity integer DEFAULT 32;
url varchar := 'http://mysite.com';
user_id CONSTANT integer := 10;
transaction_time CONSTANT timestamp with time zone := now();
</programlisting>
</para>
<para>
Once declared, a variable's value can be used in later initialization
expressions in the same block, for example:
<programlisting>
DECLARE
x integer := 1;
y integer := x + 1;
</programlisting>
</para>