PG_ENSURE_ERROR_CLEANUP and nested blocks

From: "Euler Taveira" <euler(at)eulerto(dot)com>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: PG_ENSURE_ERROR_CLEANUP and nested blocks
Date: 2026-07-27 14:56:46
Message-ID: a690b47b-1859-4598-8541-286e48e7a724@app.fastmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

If you use PG_ENSURE_ERROR_CLEANUP with nested blocks, the compiler warns about
shadow locals. There is no harm since each PG_TRY and PG_CATCH uses its own
context stack. The current code doesn't have an example of such usage but
pglogical [1] does. I don't know if other extensions have the same issue too.

The PG_TRY and PG_CATCH already accept an optional parameter (commit
112f0225dbfe) to avoid this exact issue. Since PG_ENSURE_ERROR_CLEANUP /
PG_END_ENSURE_ERROR_CLEANUP already use PG_TRY / PG_CATCH, add an optional
parameter too. (I opted to a variadic argument argument -- mimicking how PG_TRY
already handles its optional suffix parameter -- because it avoids changing existing callers).

[1] https://github.com/2ndQuadrant/pglogical/issues/521#issuecomment-4925354899

--
Euler Taveira
EDB https://www.enterprisedb.com/

Attachment Content-Type Size
v1-0001-Avoid-shadowing-variables-for-nested-PG_ENSURE_ER.patch text/x-patch 2.3 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message ayoub.kazar 2026-07-27 15:07:41 Re: [PATCH] Rewrite undirected edge patterns in GRAPH_TABLE using UNION ALL
Previous Message Chengpeng Yan 2026-07-27 14:53:23 Re: Partition pruning can incorrectly exclude a RANGE default partition