Skip to content

Commit

Permalink
Pivot: Add limitations section
Browse files Browse the repository at this point in the history
  • Loading branch information
szarnyasg committed Nov 13, 2024
1 parent 98e4a53 commit 219c1f7
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/sql/statements/pivot.md
Original file line number Diff line number Diff line change
Expand Up @@ -364,3 +364,31 @@ PIVOT (
Below is the full syntax diagram of the SQL Standard version of the `PIVOT` statement.

<div id="rrdiagram2"></div>

## Limitations

`PIVOT` currently only accepts an aggregate function, expressions are not allowed.
For example, the following query attempts to get the population as the number of people instead of thousands of people (i.e., instead of 564, get 564000):

```sql
PIVOT cities
ON year
USING sum(population) * 1000;
```

However, it fails with the following error:

```console
Catalog Error: * is not an aggregate function
```

To work around this limitation, perform the `PIVOT` with the aggregation only, then use the [`COLUMNS` expression]({% link docs/sql/expressions/star.md %}#columns-expression):

```sql
SELECT country, name, 1000 * COLUMNS(* EXCLUDE (country, name))
FROM (
PIVOT cities
ON year
USING sum(population)
);
```

0 comments on commit 219c1f7

Please sign in to comment.