Skip to content

Commit 0e1715e

Browse files
feat: add support for DuckDB CREATE TABLE with STRUCT(..) columns
Signed-off-by: Andreas Reichel <[email protected]>
1 parent 2ff7342 commit 0e1715e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8144,6 +8144,19 @@ ColDataType ColDataType():
81448144
}
81458145
{
81468146
(
8147+
(
8148+
<K_STRUCT>
8149+
"("
8150+
( tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER> )
8151+
colDataType = ColDataType() { argumentsStringList.add( tk.image + " " + colDataType.toString()); }
8152+
[
8153+
","
8154+
( tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER> )
8155+
colDataType = ColDataType() { argumentsStringList.add( tk.image + " " + colDataType.toString()); }
8156+
]
8157+
")" { colDataType = new ColDataType("STRUCT"); }
8158+
)
8159+
|
81478160
LOOKAHEAD(2) (
81488161
colDataType = DataType()
81498162
)

src/test/java/net/sf/jsqlparser/statement/select/DuckDBTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,15 @@ void testFileTable() throws JSQLParserException {
2525

2626
Assertions.assertEquals("'/tmp/test.parquet'", table.getName());
2727
}
28+
29+
@Test
30+
void testCreateWithStruct() throws JSQLParserException {
31+
String sqlStr =
32+
"CREATE TABLE starbake.array_test (\n" +
33+
" keys VARCHAR[] NOT NULL,\n" +
34+
" values1 struct( field1 varchar(255), field2 double) NOT NULL,\n" +
35+
" values2 struct( field1 varchar(255), field2 double) NOT NULL\n" +
36+
");";
37+
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
38+
}
2839
}

0 commit comments

Comments
 (0)