Skip to content

Commit fffd23b

Browse files
committed
fix: allow sample and extend as unquoted identifiers
Signed-off-by: 付典 <fudianchn@gmail.com>
1 parent 8d12a5d commit fffd23b

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6863,7 +6863,9 @@ String RelObjectName() :
68636863
| tk=<K_ON> | tk=<K_OPTIMIZE> | tk=<K_ORDER> | tk=<K_PROCEDURE>
68646864
| tk=<K_PUBLIC> | tk=<K_QUALIFY> | tk=<K_RIGHT> | tk=<K_FILE>
68656865
| tk=<K_SET> | tk=<K_SOME> | tk=<K_START> | tk=<K_TABLES>
6866-
| tk=<K_TOP> | tk=<K_VALUE> | tk=<K_VALUES> )
6866+
| tk=<K_TOP> | tk=<K_VALUE> | tk=<K_VALUES>
6867+
| tk=<K_SAMPLE>
6868+
| tk=<K_EXTEND> )
68676869
)
68686870
{ return result != null ? result : tk.image; }
68696871
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,19 @@ public void testGroupsAsIdentifier() throws JSQLParserException {
6262
assertSqlCanBeParsedAndDeparsed("SELECT a groups FROM mytable", true);
6363
assertSqlCanBeParsedAndDeparsed("CREATE TABLE mytable (groups INT)", true);
6464
}
65+
66+
// sample and extend are non-reserved in the common dialects and reach the
67+
// parser as ordinary table and column names in downstream rewriting tools.
68+
@Test
69+
public void testSampleExtendAsIdentifier() throws JSQLParserException {
70+
assertSqlCanBeParsedAndDeparsed("SELECT sample, extend FROM mytable", true);
71+
assertSqlCanBeParsedAndDeparsed("SELECT mytable.extend FROM mytable", true);
72+
assertSqlCanBeParsedAndDeparsed("SELECT * FROM mytable WHERE extend = 'x'", true);
73+
assertSqlCanBeParsedAndDeparsed("UPDATE mytable SET sample = 1, extend = 'x' WHERE id = 1", true);
74+
assertSqlCanBeParsedAndDeparsed("INSERT INTO mytable (sample, extend) VALUES (1, 'x')", true);
75+
assertSqlCanBeParsedAndDeparsed("SELECT * FROM sample", true);
76+
assertSqlCanBeParsedAndDeparsed("DELETE FROM sample WHERE extend = 'x'", true);
77+
assertSqlCanBeParsedAndDeparsed("INSERT INTO sample (extend) VALUES ('x')", true);
78+
assertSqlCanBeParsedAndDeparsed("SELECT a AS sample, b AS extend FROM mytable", true);
79+
}
6580
}

0 commit comments

Comments
 (0)