A typical database table might look something like this:
date-------geography---clicks---cost---conversions
___________________________________________________
1/1/2010---Kansas------56-------12-----1
When transposed, it looks like this.
date-----geography---metric_name---metric_value
____________________________________________
1/1/2010-Kansas------clicks--------56
1/1/2010-Kansas------cost----------12
1/1/2010-Kansas------conversions---1
The transposed table works better for some use cases where the number of metrics being collected changes frequently.
Is there a standard name for a table structured like that in the transposed table?
Best Answer
Unpivot Table
Being the product of a transformation, your desired form here is called an "Unpivot table". The form you're starting from here is either normalized data, or the result of a transformation itself called a "pivot."
You can pivot and unpivot without losing data. Pivoting and operations like this emerge from OLAP functionality, where they're rotations. In PostgreSQL we pivot with the
tablefunc
module. We can easily unpivot with aCROSS JOIN LATERAL
on aVALUES
list,Or, though slower, we use the
unnest(ARRAY[])
idiom and parallel unnestEither way you'll produce,
See also,