Crosstab Patterns (PostgreSQL crosstab())
Generate true pivot tables with the tablefunc extension's crosstab() function.
Why True Crosstab?
CASE pivots require you to list each target column. For genuinely wide pivots (e.g. one column per product), the tablefunc extension's crosstab() is the tool.
Enabling the Extension
tablefunc ships with PostgreSQL contrib:
CREATE EXTENSION IF NOT EXISTS tablefunc;All lessons in this course
- UNION, INTERSECT, EXCEPT
- UNION ALL vs UNION (Deduplication Cost)
- CASE Expressions and Pivot Queries
- Crosstab Patterns (PostgreSQL crosstab())