Skip to content

Commit 1ad4234

Browse files
feat: AllColumns, DuckDB uses EXCLUDE instead of EXCEPT
Signed-off-by: Andreas Reichel <andreas@manticore-projects.com>
1 parent f4b40e4 commit 1ad4234

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

src/main/java/net/sf/jsqlparser/statement/select/AllColumns.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,20 @@
2121
public class AllColumns extends ASTNodeAccessImpl implements Expression {
2222
protected ExpressionList<Column> exceptColumns;
2323
protected List<SelectItem<Column>> replaceExpressions;
24+
private String exceptKeyword;
2425

2526
public AllColumns(ExpressionList<Column> exceptColumns,
2627
List<SelectItem<Column>> replaceExpressions) {
2728
this.exceptColumns = exceptColumns;
2829
this.replaceExpressions = replaceExpressions;
30+
this.exceptKeyword = exceptColumns !=null ? "Except" : null;
31+
}
32+
33+
public AllColumns(ExpressionList<Column> exceptColumns,
34+
List<SelectItem<Column>> replaceExpressions, String exceptKeyword) {
35+
this.exceptColumns = exceptColumns;
36+
this.replaceExpressions = replaceExpressions;
37+
this.exceptKeyword = exceptKeyword;
2938
}
3039

3140
public AllColumns() {
@@ -66,10 +75,19 @@ public AllColumns setReplaceExpressions(List<SelectItem<Column>> replaceExpressi
6675
return this;
6776
}
6877

78+
public String getExceptKeyword() {
79+
return exceptKeyword;
80+
}
81+
82+
public AllColumns setExceptKeyword(String exceptKeyword) {
83+
this.exceptKeyword = exceptKeyword;
84+
return this;
85+
}
86+
6987
public StringBuilder appendTo(StringBuilder builder) {
7088
builder.append("*");
7189
if (exceptColumns != null && !exceptColumns.isEmpty()) {
72-
builder.append(" Except( ");
90+
builder.append(" ").append(exceptKeyword).append("( ");
7391
exceptColumns.appendTo(builder);
7492
builder.append(" )");
7593
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2632,14 +2632,16 @@ AllColumns AllColumns():
26322632
{
26332633
ParenthesedExpressionList<Column> exceptColumns = null;
26342634
List<SelectItem<Column>> replaceExpressions = null;
2635+
String exceptKeyword=null;
2636+
Token tk;
26352637
}
26362638
{
26372639
"*"
2638-
[ LOOKAHEAD(2) <K_EXCEPT> exceptColumns = ParenthesedColumnList() ]
2640+
[ LOOKAHEAD(2) ( tk=<K_EXCEPT> | tk=<K_EXCLUDE> ) exceptColumns = ParenthesedColumnList() { exceptKeyword=tk.image; } ]
26392641
[ LOOKAHEAD(2) <K_REPLACE> "(" replaceExpressions = ColumnSelectItemsList() ")" ]
26402642

26412643
{
2642-
return new AllColumns(exceptColumns, replaceExpressions);
2644+
return new AllColumns(exceptColumns, replaceExpressions, exceptKeyword);
26432645
}
26442646
}
26452647

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ class AllColumnsTest {
1919
@Test
2020
void testBigQuerySyntax() throws JSQLParserException {
2121
String sqlStr =
22-
"SELECT * EXCEPT (order_id) REPLACE (\"widget\" AS item_name), \"more\" as more_fields\n"
22+
"SELECT * EXCEPT(order_id) REPLACE(\"widget\" AS item_name), \"more\" as more_fields\n"
23+
+ "FROM orders";
24+
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
25+
}
26+
27+
@Test
28+
void testDuckDBQuerySyntax() throws JSQLParserException {
29+
String sqlStr =
30+
"SELECT * EXCLUDE(order_id) REPLACE(\"widget\" AS item_name), \"more\" as more_fields\n"
2331
+ "FROM orders";
2432
TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);
2533
}

0 commit comments

Comments
 (0)