Document that PG_TRY block cannot have a return statement
Hackorum builds and tests every patch posted to the lists, not only commitfest submissions. This is Hackorum's own CI rather than the PostgreSQL project's, and it is still under testing - please report anything that looks wrong.
You can run a PostgreSQL built from this patch straight from Docker, with no checkout and no build:
docker run --rm -p 5432:5432 ghcr.io/hackorum-dev/postgres-patch:t48436psql -h localhost -U postgresBuilt from patchset v4 (message #4), September 20, 2026 at 10:44 AM.
Every patchset is also pushed to a branch of our PostgreSQL fork, so you can check out the same tree CI built. Without a PostgreSQL checkout:
git clone --branch t48436_4 https://github.com/hackorum-dev/postgres.gitIn a checkout you already have, add the fork once:
git remote add hackorum https://github.com/hackorum-dev/postgres.gitthen, for this patchset and every later one:
git fetch hackorum t48436_4 && git checkout t48436_4Patchset v4 (message #4) is on t48436_4
Hi,
I created a tiny patch that documents that the code block following
PG_TRY() cannot have any return statement.
Please CC me, as I'm not subscribed to this list.
Attachments:
0001-note-no-return-in-pg_try.patchtext/x-patch; charset=US-ASCII; name=0001-note-no-return-in-pg_try.patchDownload+2-0
Serpent <serpent7776@gmail.com> writes:
I created a tiny patch that documents that the code block following
PG_TRY() cannot have any return statement.
AFAIK, this is wrong. The actual requirement is already stated
in the comment:
* ... The error recovery code
* can either do PG_RE_THROW to propagate the error outwards, or do a
* (sub)transaction abort.
regards, tom lane
Serpent <serpent7776@gmail.com> writes:
I'm talking about this part:
PG_TRY();
{
... code that might throw ereport(ERROR) ...
}
Ah. Your phrasing needs work for clarity then. Also, "return"
is hardly the only way to break it; break, continue, or goto
leading out of the PG_TRY are other possibilities. Maybe more
like "The XXX code must exit normally (by control reaching
the end) if it does not throw ereport(ERROR)." Not quite sure
what to use for XXX.
regards, tom lane
Import Notes
Reply to msg id not found: CANncwrKVtHJupo+xCO9+GGvq92STQr--sq4Z4kPXzUrJko7g@mail.gmail.com
Hi,
What about this wording:
The code that might throw ereport(ERROR) cannot contain any non local
control flow other than ereport(ERROR) e.g.: return, goto, break, continue.
In other words once PG_TRY() is executed, either PG_CATCH() or PG_FINALLY()
must be executed as well.
I used 'code that might throw ereport(ERROR)' for XXX since this is what's
used earlier in the comment.
On Tue, 12 Sept 2023 at 17:22, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Show quoted text
Serpent <serpent7776@gmail.com> writes:
I'm talking about this part:
PG_TRY();
{
... code that might throw ereport(ERROR) ...
}Ah. Your phrasing needs work for clarity then. Also, "return"
is hardly the only way to break it; break, continue, or goto
leading out of the PG_TRY are other possibilities. Maybe more
like "The XXX code must exit normally (by control reaching
the end) if it does not throw ereport(ERROR)." Not quite sure
what to use for XXX.regards, tom lane
LGTM!
Serpent <serpent7776@gmail.com> 于2024年8月15日周四 15:01写道:
Hi,
What about this wording:
The code that might throw ereport(ERROR) cannot contain any non local
control flow other than ereport(ERROR) e.g.: return, goto, break, continue.
In other words once PG_TRY() is executed, either PG_CATCH() or
PG_FINALLY() must be executed as well.I used 'code that might throw ereport(ERROR)' for XXX since this is what's
used earlier in the comment.On Tue, 12 Sept 2023 at 17:22, Tom Lane <tgl@sss.pgh.pa.us> wrote:
Serpent <serpent7776@gmail.com> writes:
I'm talking about this part:
PG_TRY();
{
... code that might throw ereport(ERROR) ...
}Ah. Your phrasing needs work for clarity then. Also, "return"
is hardly the only way to break it; break, continue, or goto
leading out of the PG_TRY are other possibilities. Maybe more
like "The XXX code must exit normally (by control reaching
the end) if it does not throw ereport(ERROR)." Not quite sure
what to use for XXX.regards, tom lane
--
Best regards !
Xiaoran Wang