make all ereport in gram.y print out relative location

jian he <jian.universality@gmail.com>

From: jian he <jian.universality@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2024-10-26T15:12:37Z
Lists: pgsql-hackers

Attachments

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.

Commits

  1. Add a parse location field to struct FunctionParameter.

  2. Make all ereport() calls within gram.y provide error locations.