# tablefunc — Postgres extension

> Crosstab and other table functions.

Source: https://scribase.com/extensions/tablefunc

Category: Development. Version: 1.0. Optional, enabled per project.

## About

tablefunc provides crosstab for pivoting rows into columns, connectby for walking parent-child tables, and normal_rand for generating normally distributed test data.

## Enable it

```sql
create extension if not exists tablefunc with schema extensions;
```

## Example

```sql
select * from crosstab(
  $$select region, quarter, sum(amount) from sales group by 1, 2 order by 1, 2$$,
  $$select unnest(array['Q1', 'Q2', 'Q3', 'Q4'])$$
) as pivot(region text, q1 numeric, q2 numeric, q3 numeric, q4 numeric);
```

Upstream: https://www.postgresql.org/docs/17/tablefunc.html