select open change scope Open full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

FUNCTIONS / TEXT SEARCH FUNCTIONS AND OPERATORS

Expands a tsvector into a set of rows, one per lexeme.

Signatures & examples

unnest ( tsvector ) → setof record ( lexeme text, positions smallint[], weights text )
Expands a tsvector into a set of rows, one per lexeme.
select * from unnest('cat:3 fat:2,4 rat:5A'::tsvector) →  lexeme | positions | weights
--------+-----------+---------
 cat    | {3}       | {D}
 fat    | {2,4}     | {D,D}
 rat    | {5}       | {A}
unnest ( anyarray ) → setof anyelement
Expands an array into a set of rows. The array's elements are read out in storage order.
unnest(ARRAY[1,2]) → 1
2
unnest(ARRAY[['foo','bar'],['baz','quux']]) → foo
bar
baz
quux
unnest ( anyarray, anyarray [, ... ] ) → setof anyelement, anyelement [, ... ]
Expands multiple arrays (possibly of different data types) into a set of rows. If the arrays are not all the same length then the shorter ones are padded with NULLs. This form is only allowed in a query's FROM clause; see Section 7.2.1.4.
select * from unnest(ARRAY[1,2], ARRAY['foo','bar','baz']) as x(a,b) →  a |  b
---+-----
 1 | foo
 2 | bar
   | baz
unnest ( anymultirange ) → setof anyrange
Expands a multirange into a set of ranges in ascending order.
unnest('{[1,2), [3,4)}'::int4multirange) → [1,2)
[3,4)
Version history 4
  1. PG 13 → 14changed
  2. PG 12 → 13changed
  3. PG 9.5 → 9.6changed
  4. PG 9.3 → 9.4changed

Definition snapshot: 2026-09-14T13:14:25.684213+00:00@99e6866c · English manual source