Modern SQL: Lateral
Lateral is the “for each” loop of SQL
.. Lateral is great for Top-N subqueries
.. In PostgreSQL “With” view are more like materialized views
With deleted_rows AS (
Delete from source_tbl
Returning *
)
Insert into destination_tbl
Select * from deleted_rows;