Skip to content

Table functions ​

A table function appears in FROM and supplies rows with a documented schema. It can be filtered, joined or aggregated like another query source.

Sources ​

Source Use
generate_series Generate inclusive numeric or calendar values.
file Read a confined server-side file with an input format.
unnest, generate_subscripts Expand arrays or enumerate their positions.
string_to_table, regexp_split_to_table Split text into rows.
regexp_matches Return regular-expression matches as rows.
json_each, json_tree and JSON/JSONB expanders Read JSON members, paths or typed records as rows.

The array, JSON, splitting and search references specify their arguments and output columns. Typed JSON record sources can require an AS alias(column Type, ...) schema.

Example ​

Aggregating generated rows ​

sql
SELECT count(*) AS rows, sum(generate_series) AS total
FROM generate_series(1, 5)
FORMAT csv;
text
5,15

Use the documented FROM form. A function returning rows is not interchangeable with a scalar function returning an Array or JSON value.