Skip to content

Commit edfbb0a

Browse files
authored
fix: allow GROUPS as identifier by making it a non-reserved keyword (#2473) (#2474)
Signed-off-by: 付典 <fudianchn@gmail.com>
1 parent 406a4d4 commit edfbb0a

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1287,6 +1287,7 @@ String NonReservedWord() :
12871287
| tk=<K_FULLTEXT:"FULLTEXT">
12881288
| tk=<K_FUNCTION:"FUNCTION">
12891289
| tk=<K_GRANT:"GRANT">
1290+
| tk=<K_GROUPS:"GROUPS">
12901291
| tk=<K_GROUP_CONCAT:"GROUP_CONCAT">
12911292
| tk=<K_GUARD:"GUARD">
12921293
| tk=<K_HASH:"HASH">
@@ -1577,7 +1578,6 @@ TOKEN: /* Reserved SQL Keywords and structural tokens */
15771578
| <K_GLOBAL:"GLOBAL">
15781579
| <K_GROUP:"GROUP">
15791580
| <K_GROUPING:"GROUPING">
1580-
| <K_GROUPS:"GROUPS">
15811581
| <K_HAVING:"HAVING">
15821582
| <K_IF:"IF">
15831583
| <K_IIF:"IIF">

src/test/java/net/sf/jsqlparser/statement/KeywordsTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,15 @@ public void testCombinedTokenKeywords() throws JSQLParserException {
5151
String sqlStr = "SELECT current_date(3)";
5252
assertSqlCanBeParsedAndDeparsed(sqlStr, true);
5353
}
54+
55+
// #2473: GROUPS is a non-reserved keyword in PostgreSQL and must stay usable as an
56+
// identifier, although it also introduces the GROUPS window frame unit.
57+
@Test
58+
public void testGroupsAsIdentifier() throws JSQLParserException {
59+
assertSqlCanBeParsedAndDeparsed("SELECT groups FROM mytable", true);
60+
assertSqlCanBeParsedAndDeparsed("SELECT * FROM groups", true);
61+
assertSqlCanBeParsedAndDeparsed("SELECT a AS groups FROM mytable", true);
62+
assertSqlCanBeParsedAndDeparsed("SELECT a groups FROM mytable", true);
63+
assertSqlCanBeParsedAndDeparsed("CREATE TABLE mytable (groups INT)", true);
64+
}
5465
}

0 commit comments

Comments
 (0)