-
Notifications
You must be signed in to change notification settings - Fork 70
Fix ON CONFLICT subqueries referencing excluded rows #345
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
Changes from 1 commit
d31be3f
262dd96
a0ce002
7bc6ad8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1899,6 +1899,39 @@ TEST_P(QueryEngineTest, InsertOnConflictDoUpdateDml) { | |
| EXPECT_EQ(result.modified_row_count, 2); | ||
| } | ||
|
|
||
| TEST_P(QueryEngineTest, InsertOnConflictDoUpdateSubqueryCanReferenceExcluded) { | ||
| if (GetParam() == POSTGRESQL) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should work for PG as well. Do we need this GTEST_SKIP?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| GTEST_SKIP() << "GoogleSQL-specific regression test"; | ||
| } | ||
|
|
||
| MockRowWriter writer; | ||
| EXPECT_CALL( | ||
| writer, | ||
| Write(Property( | ||
| &Mutation::ops, | ||
| UnorderedElementsAre(AllOf( | ||
| Field(&MutationOp::type, MutationOpType::kUpdate), | ||
| Field(&MutationOp::table, "test_table"), | ||
| Field(&MutationOp::columns, | ||
| std::vector<std::string>{"int64_col", "string_col"}), | ||
| Field(&MutationOp::rows, | ||
| UnorderedElementsAre(ValueList{Int64(1), String("ten")}))))))) | ||
| .Times(1) | ||
| .WillOnce(Return(absl::OkStatus())); | ||
|
|
||
| GOOGLESQL_ASSERT_OK_AND_ASSIGN( | ||
| QueryResult result, | ||
| query_engine().ExecuteSql( | ||
| Query{"INSERT INTO test_table (int64_col, string_col) " | ||
| "VALUES(1, 'ten') " | ||
| "ON CONFLICT(int64_col) DO UPDATE SET string_col = " | ||
| "(SELECT excluded.string_col)"}, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe good to replace this with a subquery that does a table scan as well: This will change the output
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
| QueryContext{schema(), reader(), &writer})); | ||
|
|
||
| ASSERT_EQ(result.rows, nullptr); | ||
| EXPECT_EQ(result.modified_row_count, 1); | ||
| } | ||
|
|
||
| TEST_P(QueryEngineTest, InsertOnConflictDoUpdateDmlWithReturning) { | ||
| std::string returning = | ||
| (GetParam() == POSTGRESQL) ? "RETURNING" : "THEN RETURN WITH ACTION"; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing this issue and adding a fix.
Can we pls add a comment here - "Replace the column references from insert row with the insert row value struct"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done