[postgresql] Fix for #4309, #4315, #4318. #4319
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is a fix for #4309, #4315, and #4318.
This change corrects a lot of issues with the PostgreSQL grammar. The overall issue was that there were still a number of pl/pgsql grammar rules in this grammar even after #4316. As I mentioned, adding the grammar for pl/pgsql directly into the PostgreSQL grammar causes a lot of problems. It is very important to learn from this: you should not merge in the grammar for pl/pgsql into PostgreSQL, unless you are very, very careful. For example, you would have to have every lexer by default work in a different lexer mode. The official parser for PostgreSQL does not try to combine grammars. Why should the Antlr grammar deviate from this?
The changes bring the grammar to be back in line with the official PostgreSQL grammar gram.y. All the tests pass, but more importantly, the ambiguities that I mentioned are now gone. This is because the official Bison grammar is LALR(1), so it shouldn't be ambiguous.
It's not clear if I still have all the pl/pgsql grammar removed from the postgresql grammar. There was one test that uses embedded SQL identifiers, but it shouldn't. So PLSQLVARIABLENAME is still defined and used.
I noticed that the lexer grammar contained numerous "built-in" function names. These were added erroneously. I added the comments from gram.y for the identifier classes into the parser grammar.