Write a MERGE statement covering both matched and not matched cases with insert, update and delete.
Asked in the Technical round 1 stage. For grading, model the MERGE behavior with Python. The target and source are lists of dictionaries keyed by id. Each source row has id, value, and operation, where operation is update, delete, or insert.
Return the merged target rows as a list. For a matched key, update replaces the target row and delete removes it. For an unmatched key, insert adds the source row. Preserve target order, then append newly inserted rows in source order.
def merge_records(target, source):