Skip to content

Commit

Permalink
Support INSERT DEFAULT VALUES in MERGE
Browse files Browse the repository at this point in the history
  • Loading branch information
nene committed Jan 8, 2024
1 parent ab1dc04 commit d041bfc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/cst/Merge.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Alias } from "./Alias";
import { BaseNode, Keyword } from "./Base";
import { Expr, Identifier, ListExpr, ParenExpr, EntityName } from "./Expr";
import { ValuesClause } from "./Insert";
import { DefaultValues, ValuesClause } from "./Insert";
import { SelectStmt, WithClause } from "./Select";
import { SetClause } from "./Update";

Expand Down Expand Up @@ -82,9 +82,10 @@ export interface MergeActionInsert extends BaseNode {
type: "merge_action_insert";
insertKw: Keyword<"INSERT">;
columns?: ParenExpr<ListExpr<Identifier>>;
values: ValuesClause | MergeActionInsertRowClause;
values: ValuesClause | DefaultValues | MergeActionInsertRowClause;
}

// BigQuery
export interface MergeActionInsertRowClause extends BaseNode {
type: "merge_action_insert_row_clause";
rowKw: Keyword<"ROW">;
Expand Down
17 changes: 9 additions & 8 deletions src/parser.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,14 +1732,15 @@ merge_action_update
}

merge_action_insert
= insertKw:(INSERT __) columns:(paren$list$column __)? values:(values_clause / merge_action_insert_row_clause) {
return loc({
type: "merge_action_insert",
insertKw: read(insertKw),
columns: read(columns),
values,
});
}
= insertKw:(INSERT __) columns:(paren$list$column __)?
values:(values_clause / default_values / merge_action_insert_row_clause) {
return loc({
type: "merge_action_insert",
insertKw: read(insertKw),
columns: read(columns),
values,
});
}

merge_action_insert_row_clause
= rowKw:ROW &bigquery {
Expand Down
6 changes: 6 additions & 0 deletions test/dml/merge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ describe("merge into", () => {
);
});

dialect("postgresql", () => {
it("supports INSERT DEFAULT VALUES", () => {
testWc("MERGE INTO foo USING bar ON x=y WHEN NOT MATCHED THEN INSERT DEFAULT VALUES");
});
});

dialect("bigquery", () => {
it("supports INSERT ROW", () => {
testWc("MERGE INTO foo USING bar ON x=y WHEN NOT MATCHED THEN INSERT ROW");
Expand Down

0 comments on commit d041bfc

Please sign in to comment.