Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support PostgreSQL do nothing conflict action #31048

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,10 @@ public ASTNode visitInsert(final InsertContext ctx) {

@Override
public ASTNode visitOptOnConflict(final OptOnConflictContext ctx) {
SetClauseListContext setClauseListContext = ctx.setClauseList();
Collection<ColumnAssignmentSegment> assignments = ((SetAssignmentSegment) visit(setClauseListContext)).getAssignments();
Collection<ColumnAssignmentSegment> assignments = new LinkedList<>();
if (null != ctx.setClauseList()) {
assignments = ((SetAssignmentSegment) visit(ctx.setClauseList())).getAssignments();
}
return new OnDuplicateKeyColumnsSegment(ctx.getStart().getStartIndex(), ctx.getStop().getStopIndex(), assignments);
}

Expand Down
16 changes: 16 additions & 0 deletions test/it/parser/src/main/resources/case/dml/insert.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4140,4 +4140,20 @@
</value>
</values>
</insert>

<insert sql-case-id="insert_into_with_conflict_action_do_nothing" parameters="1">
<table name="sj_event" start-index="12" stop-index="19" />
<columns start-index="20" stop-index="29">
<column name="event_id" start-index="21" stop-index="28" />
</columns>
<values>
<value>
<assignment-value>
<parameter-marker-expression parameter-index="0" start-index="39" stop-index="39" />
<literal-expression value="1" start-index="39" stop-index="39" />
</assignment-value>
</value>
</values>
<on-duplicate-key-columns start-index="42" stop-index="73"/>
</insert>
</sql-parser-test-cases>
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,5 @@
<sql-case id="insert_with_output_input" value="INSERT Production.ScrapReason OUTPUT INSERTED.ScrapReasonID, INSERTED.Name, INSERTED.ModifiedDate INTO @MyTableVar VALUES (N'Operator error', GETDATE())" db-types="SQLServer"/>
<sql-case id="insert_into_with_multi_nchar" value="INSERT INTO Production.UnitMeasure VALUES (N'FT2', N'Square Feet ', '20080923'), (N'Y', N'Yards', '20080923'), (N'Y3', N'Cubic Yards', '20080923')" db-types="SQLServer"/>
<sql-case id="insert_into_with_select_with_merge" value="INSERT INTO Production.ZeroInventory (DeletedProductID, RemovedOnDate) SELECT ProductID, GETDATE() FROM (MERGE Production.ProductInventory AS pi USING (SELECT ProductID, SUM(OrderQty) FROM Sales.SalesOrderDetail AS sod JOIN Sales.SalesOrderHeader AS soh ON sod.SalesOrderID = soh.SalesOrderID AND soh.OrderDate = '20070401' GROUP BY ProductID) AS src (ProductID, OrderQty) ON (pi.ProductID = src.ProductID) WHEN MATCHED AND pi.Quantity - src.OrderQty &lt;= 0 THEN DELETE WHEN MATCHED THEN UPDATE SET pi.Quantity = pi.Quantity - src.OrderQty OUTPUT $action, deleted.ProductID) AS Changes (Action, ProductID) WHERE Action = 'DELETE'" db-types="SQLServer"/>
<sql-case id="insert_into_with_conflict_action_do_nothing" value="INSERT INTO sj_event(event_id) VALUES (?) ON CONFLICT(event_id) DO NOTHING" db-types="PostgreSQL"/>
</sql-cases>