| From: | jian he <jian(dot)universality(at)gmail(dot)com> |
|---|---|
| To: | Corey Huinker <corey(dot)huinker(at)gmail(dot)com> |
| Cc: | Amul Sul <sulamul(at)gmail(dot)com>, Kirill Reshke <reshkekirill(at)gmail(dot)com>, Vik Fearing <vik(at)postgresfriends(dot)org>, Isaac Morland <isaac(dot)morland(at)gmail(dot)com>, pgsql-hackers(at)lists(dot)postgresql(dot)org |
| Subject: | Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions |
| Date: | 2026-03-13 05:48:26 |
| Message-ID: | CACJufxE7yoH42juViFvYuCQMPwXMWxDVwiugs-BW+N4oUXB=1w@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
On Fri, Mar 13, 2026 at 11:59 AM Corey Huinker <corey(dot)huinker(at)gmail(dot)com> wrote:
>
> Can you explain this bit below?
>
> @@ -595,13 +605,23 @@ RangeVarGetRelidExtended(const RangeVar *relation, LOCKMODE lockmode,
> {
> int elevel = (flags & RVR_SKIP_LOCKED) ? DEBUG1 : ERROR;
>
> - if (relation->schemaname)
> - ereport(elevel,
> + if (relation->schemaname && elevel == DEBUG1)
> + ereport(DEBUG1,
> (errcode(ERRCODE_LOCK_NOT_AVAILABLE),
> errmsg("could not obtain lock on relation \"%s.%s\"",
> relation->schemaname, relation->relname)));
> - else
> - ereport(elevel,
> + else if (relation->schemaname && elevel == ERROR)
> + ereturn(escontext, InvalidOid,
> + errcode(ERRCODE_LOCK_NOT_AVAILABLE),
> + errmsg("could not obtain lock on relation \"%s.%s\"",
> + relation->schemaname, relation->relname));
> + else if (elevel == DEBUG1)
> + ereport(DEBUG1,
> + errcode(ERRCODE_LOCK_NOT_AVAILABLE),
> + errmsg("could not obtain lock on relation \"%s\"",
> + relation->relname));
> + else if (elevel == ERROR)
> + ereturn(escontext, InvalidOid,
>
This is for supporting casting text to regclass error safe, for example:
SELECT CAST('abc'::text as regclass default NULL on conversion error);
To do that, we need to refactor the RangeVarGetRelidExtended function
to make it error-safe.
We can also change it as:
if (relation->schemaname)
{
if (elevel == DEBUG1)
ereport(DEBUG1,
(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
errmsg("could not obtain lock on relation \"%s.%s\"",
relation->schemaname, relation->relname)));
else
ereturn(escontext, InvalidOid,
errcode(ERRCODE_LOCK_NOT_AVAILABLE),
errmsg("could not obtain lock on relation \"%s.%s\"",
relation->schemaname, relation->relname));
}
else
{
if (elevel == DEBUG1)
ereport(DEBUG1,
errcode(ERRCODE_LOCK_NOT_AVAILABLE),
errmsg("could not obtain lock on relation \"%s\"",
relation->relname));
else
ereturn(escontext, InvalidOid,
(errcode(ERRCODE_LOCK_NOT_AVAILABLE),
errmsg("could not obtain lock on relation \"%s\"",
relation->relname)));
}
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Yi Ding | 2026-03-13 05:51:25 | Re:Re: Change COPY ... ON_ERROR ignore to ON_ERROR ignore_row |
| Previous Message | Ashutosh Sharma | 2026-03-13 05:09:40 | Re: Report bytes and transactions actually sent downtream |