Company
Date Published
July 21, 2022
Author
Claire Carroll
Word count
1035
Language
English
Hacker News points
2

Summary

CTEs (Common Table Expressions) are temporary, named result sets that can be referenced within the same query. They were introduced in SQL in 2005 and have become popular due to their modularity, reusability, recursion, and referenceability. However, they can only be referenced in the same query where they were created, making debugging complex queries difficult. Chained SQL is a feature that allows breaking up long CTE-based queries into separate chunks that can reference each other, improving readability and debuggability. Hex's Chained SQL automatically turns references to upstream results into CTEs behind the scenes, utilizing caching for efficient query execution.