I wrote:
> I wonder whether we could improve matters by adjusting the heuristic for
> such things in pl_scanner.c:
>
> * If we are at start of statement, prefer unreserved keywords
> * over variable names, unless the next token is assignment or
> * '[', in which case prefer variable names. (Note we need not
> * consider '.' as the next token; that case was handled above,
> * and we always prefer variable names in that case.) If we are
> * not at start of statement, always prefer variable names over
> * unreserved keywords.
Digging in the commit history, that code all dates to commit bb1b8f69,
which arose from a discussion about making plpgsql keywords unreserved:
https://www.postgresql.org/message-id/5030.1416778830%40sss.pgh.pa.us
AFAICS, the question of conflicts against core-parser keywords didn't
come up at all in that thread, so it's not surprising we didn't consider
that case. I don't see any indication that we explicitly rejected
doing something for that case.
There's still the question of whether there are any cases where we
*need* to recognize a variable name that's at statement start and
isn't followed by assignment or '['.
regards, tom lane