Commit 10bd173
committed
fix: correct grammar alternative ordering for RLS statements
Fixed parser failures when parsing PostgreSQL Row Level Security (RLS)
statements by reordering grammar alternatives to check more specific
patterns before less specific ones.
Problem:
- ALTER TABLE ... ENABLE/DISABLE ROW LEVEL SECURITY failed to parse
- Parser was incorrectly choosing ENABLE/DISABLE KEYS path first
- Grammar warning about WITH keyword conflict in CREATE POLICY
Solution:
1. Reordered ENABLE alternatives: ENABLE ROW LEVEL SECURITY now checked
before ENABLE KEYS (lines 9674-9684)
2. Reordered DISABLE alternatives: DISABLE ROW LEVEL SECURITY now checked
before DISABLE KEYS (lines 9661-9671)
3. Added LOOKAHEAD(2) to WITH CHECK clause in CREATE POLICY to resolve
conflict with CTEs (line 10470)
Impact:
- All 19 existing RLS tests pass (8 AlterRowLevelSecurityTest,
11 CreatePolicyTest)
- WITH keyword conflict warning eliminated
- Parser can now handle real-world SQL migration files with RLS statements
- No regressions in existing functionality
Technical Note:
In JavaCC, when multiple alternatives share a common prefix (like ENABLE),
the more specific pattern (longer token sequence) must appear FIRST in the
grammar to be matched correctly. LOOKAHEAD values help disambiguate, but
ordering is critical for correct parsing.1 parent 7e62119 commit 10bd173
File tree
2 files changed
+20
-11
lines changed- src
- main/jjtree/net/sf/jsqlparser/parser
- test/java/net/sf/jsqlparser/expression
2 files changed
+20
-11
lines changedLines changed: 11 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9657 | 9657 | | |
9658 | 9658 | | |
9659 | 9659 | | |
9660 | | - | |
9661 | | - | |
9662 | | - | |
9663 | | - | |
| 9660 | + | |
| 9661 | + | |
| 9662 | + | |
| 9663 | + | |
9664 | 9664 | | |
9665 | 9665 | | |
9666 | | - | |
9667 | 9666 | | |
9668 | 9667 | | |
9669 | | - | |
9670 | | - | |
| 9668 | + | |
| 9669 | + | |
9671 | 9670 | | |
9672 | 9671 | | |
| 9672 | + | |
9673 | 9673 | | |
9674 | 9674 | | |
9675 | 9675 | | |
9676 | 9676 | | |
9677 | 9677 | | |
9678 | 9678 | | |
9679 | 9679 | | |
9680 | | - | |
9681 | | - | |
9682 | | - | |
| 9680 | + | |
| 9681 | + | |
| 9682 | + | |
9683 | 9683 | | |
9684 | 9684 | | |
9685 | 9685 | | |
| |||
10467 | 10467 | | |
10468 | 10468 | | |
10469 | 10469 | | |
10470 | | - | |
| 10470 | + | |
10471 | 10471 | | |
10472 | 10472 | | |
10473 | 10473 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
1 | 10 | | |
2 | 11 | | |
3 | 12 | | |
| |||
0 commit comments