make all ereport in gram.y print out relative location

From: jian he <jian(dot)universality(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: make all ereport in gram.y print out relative location
Date: 2024-10-26 15:12:37
Message-ID: CACJufxEmONE3P2En=jopZy1m=cCCUs65M4+1o52MW5og9oaUPA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

hi.
it would be better to make all ereport in gram.y print out the
relative location.
one benefit is quickly locating the error.

in insertSelectOptions, some ereport won't call parser_errposition.
To handle that
I added a location to struct SelectLimit, so we can catch the location
in the LIMIT/FETCH/OFFSET clause.

in insertSelectOptions the error is
errmsg("WITH TIES cannot be specified without
ORDER BY clause"),
errmsg("%s and %s options cannot be used
together","SKIP LOCKED", "WITH TIES"),

to capture the exact location, i use the following way:
| FETCH first_or_next select_fetch_first_value
row_or_rows WITH TIES
@@ -13222,6 +13247,7 @@ limit_clause:
n->limitOffset = NULL;
n->limitCount = $3;
n->limitOption = LIMIT_OPTION_WITH_TIES;
+ n->location = @5;
$$ = n;

but normally we do `n->location = @1;`
not sure my change in insertSelectOptions is correct.

For other places in gram.y, I guess my change is sane.
i manually checked, after my patch, all ereport function calls in
gram.y will print out the relative location.

Attachment Content-Type Size
v1-0001-add-cursor-position-in-various-ereport-function-i.patch application/x-patch 17.9 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Nathan Bossart 2024-10-26 15:55:44 Re: sunsetting md5 password support
Previous Message Alvaro Herrera 2024-10-26 14:16:27 Re: Fix C23 compiler warning