throwDbException.get(ErrorCode.DUPLICATE_KEY_1,"Merge using ON column expression, duplicate _ROWID_ target record already updated, deleted or inserted:_ROWID_="
throwDbException.get(ErrorCode.GENERAL_ERROR_1,"Expected to find key after row inserted, but none found. Insert does not match ON condition.:"+targetTable.getSQL()+":source row="+Arrays.asList(sourceRow.getValueList()));
}
}
}
returnlocalCount;
returnlocalCount;
}
}
...
@@ -386,6 +430,14 @@ public class MergeUsing extends Prepared {
...
@@ -386,6 +430,14 @@ public class MergeUsing extends Prepared {
throwDbException.get(ErrorCode.SYNTAX_ERROR_1,
throwDbException.get(ErrorCode.SYNTAX_ERROR_1,
"At least UPDATE, DELETE or INSERT embedded statement must be supplied.");
"At least UPDATE, DELETE or INSERT embedded statement must be supplied.");
}
}
// setup the targetMatchQuery - for detecting if the target row exists
@@ -182,7 +182,17 @@ public class TestMergeUsing extends TestBase {
...
@@ -182,7 +182,17 @@ public class TestMergeUsing extends TestBase {
"SELECT X AS ID, 'Marcy'||X||X AS NAME FROM SYSTEM_RANGE(2,2) UNION ALL SELECT X AS ID, 'Marcy'||X AS NAME FROM SYSTEM_RANGE(3,3)",
"SELECT X AS ID, 'Marcy'||X||X AS NAME FROM SYSTEM_RANGE(2,2) UNION ALL SELECT X AS ID, 'Marcy'||X AS NAME FROM SYSTEM_RANGE(3,3)",
3,
3,
"No references to source columns found in ON clause"
"No references to source columns found in ON clause"
);
);
// Insert does not insert correct values with respect to ON condition (inserts ID value above 100, instead)
testMergeUsingException(
"CREATE TABLE PARENT AS (SELECT 1 AS ID, 'Marcy'||X AS NAME FROM SYSTEM_RANGE(4,4) );"+
"CREATE TABLE SOURCE AS (SELECT X AS ID, 'Marcy'||X AS NAME FROM SYSTEM_RANGE(1,3) );",
"MERGE INTO PARENT USING SOURCE ON (PARENT.ID = SOURCE.ID) WHEN MATCHED THEN UPDATE SET PARENT.NAME = SOURCE.NAME||SOURCE.ID WHERE PARENT.ID = 2 DELETE WHERE PARENT.ID = 1 WHEN NOT MATCHED THEN INSERT (ID, NAME) VALUES (SOURCE.ID+100, SOURCE.NAME)",
GATHER_ORDERED_RESULTS_SQL,
"SELECT X AS ID, 'Marcy'||X AS NAME FROM SYSTEM_RANGE(4,4)",
1,
"Expected to find key after row inserted, but none found. Insert does not match ON condition."