53. Upsert: Merge New Records into a Table
Difficulty: Hard · Topics: Window Functions, Filtering & Selection
An advanced problem: unlock it to open the statement, sample data and editor. Graded on 3 test cases.
Learn the concepts
- MERGE INTO and upserts · 7 min read. Matched, not-matched and not-matched-by-source clauses, step by step, and the duplicate-source error.
- The medallion architecture · 6 min read. Bronze, silver and gold layers: what belongs in each, and where the pattern goes wrong.
- Streaming into Delta tables · 7 min read. Write a stream into a Delta table exactly once, and read a Delta table as a stream.
PySpark functions you'll practise
- Row Number
- Window spec
- filter
- withColumn
- orderBy
- unionByName
Related problems
- Three-Day Login Streak · Hard · Window Functions, Aggregations, Dates, Filtering & Selection
- Consecutive Status Runs (Gaps and Islands) · Hard · Window Functions, Aggregations
- Build an SCD Type 2 History · Hard · Window Functions, Null Handling, Filtering & Selection
- Trailing 3 Calendar Days (Range Frame) · Hard · Window Functions, Dates, Filtering & Selection
- Forward-Fill Missing Readings · Hard · Window Functions
Browse
Topics: Window Functions · Joins · Aggregations · Pivot, Unpivot & Rollup · Arrays · Null Handling · Conditional Logic · Dates · Filtering & Selection · Strings · Data Lake · Lakehouse · Streaming · Data Prep for AI · Spark Performance
Difficulty: Easy · Medium · Hard · Learn · All problems · dbt practice