← unpivot operator page · clause/unpivot/basic/manual_ex_2
pandas ✅ · DuckDB ✅
unpivot Id_3, Me_2, on the measures A (Number), B and C (Integer).
Unpivoting, Example 2, output verbatim: "All the measures of op must have the same basic scalar type, including sub-types", which accepts them, as Integer is a sub-type of Number. The manual's ds_2.json names its dataset DS_1, a slip: the example loads it as DS_2, the name that the page and the script give it.
Nine data points, with Me_2 typed Number, as the manual types it. The manual prints 2.1 for (6, A) with trailing spaces, which the importer stripped, as for every non-String value.
DS_r := DS_2 [ unpivot Id_3, Me_2 ];
| Id_1 | A | B | C |
|---|---|---|---|
| 4 | 3.1 | 1 | 6 |
| 5 | 4.2 | 2 | 3 |
| 6 | 2.1 | 3 | 2 |
{
"datasets": [
{
"name": "DS_2",
"DataStructure": [
{"name": "Id_1", "type": "Integer", "role": "Identifier", "nullable": false},
{"name": "A", "type": "Number", "role": "Measure", "nullable": true},
{"name": "B", "type": "Integer", "role": "Measure", "nullable": true},
{"name": "C", "type": "Integer", "role": "Measure", "nullable": true}
]
}
]
}
| Id_1 | Id_3 | Me_2 |
|---|---|---|
| 4 | A | 3.1 |
| 5 | A | 4.2 |
| 6 | A | 2.1 |
| 4 | B | 1 |
| 5 | B | 2 |
| 6 | B | 3 |
| 4 | C | 6 |
| 5 | C | 3 |
| 6 | C | 2 |
{
"datasets": [
{
"name": "DS_r",
"DataStructure": [
{"name": "Id_1", "type": "Integer", "role": "Identifier"},
{"name": "Id_3", "type": "String", "role": "Identifier"},
{"name": "Me_2", "type": "Number", "role": "Measure"}
]
}
]
}