Provides a spreadsheet-style pivot_table function
Compatibility Matrix
This table covers all DuckDB releases that have not reached end-of-life, including LTS releases, and shows the 2 most recent patch releases of each. Older patch releases are not listed, but the extension may be available for them as well.
| Platform | 1.5.5 | 1.5.6 | 2.0.0 | 2.0.1 |
|---|---|---|---|---|
| Linux AMD64 | ||||
| Linux ARM64 | ||||
| macOS AMD64 | ||||
| macOS ARM64 | ||||
| Windows AMD64 | ||||
| Windows ARM64 | ||||
| WebAssembly |
Installing and Loading
INSTALL pivot_table FROM community;
LOAD pivot_table;
Example
FROM pivot_table(['duckdb_databases'], [], ['database_name'], [], []);
About pivot_table
This extension, pivot_table, allows you to pivot your data using a spreadsheet-like pivot API. It is also similar to the Pandas pivot_table function. It does this solely through SQL macros, which are registered through the DuckDB C extension API.
It supports row and column subtotals and grand totals (aggregated from the raw data, so averages and distinct counts are correct at every level), sorting by row fields or calculated columns, and filters. When pivoting columns outward, first compute the values to pivot out with SET VARIABLE pivot_table_column_values = pivot_table_column_values(['my_table'], ['my_column'], []);. See the README for details and examples.
Added Functions
| function_name | function_type | description | comment | examples |
|---|---|---|---|---|
| columns_values_axis_columns | macro | NULL | NULL | |
| columns_values_axis_rows | macro | NULL | NULL | |
| dq | macro | NULL | NULL | |
| dq_concat | macro | NULL | NULL | |
| dq_list | macro | NULL | NULL | |
| no_columns | macro | NULL | NULL | |
| nq | macro | NULL | NULL | |
| nq_concat | macro | NULL | NULL | |
| nq_list | macro | NULL | NULL | |
| pivot_column_names | macro | NULL | NULL | |
| pivot_column_value_sql | macro | NULL | NULL | |
| pivot_source_sql | macro | NULL | NULL | |
| pivot_table | table_macro | NULL | NULL | |
| pivot_table_column_values | macro | NULL | NULL | |
| pivot_table_show_sql | table_macro | NULL | NULL | |
| pivot_table_sql | macro | NULL | NULL | |
| resolve_column_values | macro | NULL | NULL | |
| row_label_columns | macro | NULL | NULL | |
| row_label_sql | macro | NULL | NULL | |
| row_labels_select | macro | NULL | NULL | |
| sort_pivot_sql | macro | NULL | NULL | |
| sq | macro | NULL | NULL | |
| sq_concat | macro | NULL | NULL | |
| sq_list | macro | NULL | NULL | |
| total_levels | macro | NULL | NULL |
Overloaded Functions
This extension does not add any function overloads.
Added Types
| type_name | type_size | logical_type | type_category | internal |
|---|---|---|---|---|
| VARCHAR | 16 | VARCHAR | STRING | true |
Added Settings
| name | description | input_type | scope | aliases | typed_value |
|---|---|---|---|---|---|
| temp_directory | Set the directory to which temporary files are written. | VARCHAR | GLOBAL | [] | post.db.tmp |