Select unnest postgres

  • Home
  • PostgreSQL Home
  • ▼PostgreSQL ARRAY functions
  • ARRAY_APPEND function
  • ARRAY_CAT function
  • ARRAY_NDIMS function
  • ARRAY_DIMS function
  • ARRAY_FILL function
  • ARRAY_LENGTH function
  • ARRAY_LOWER function
  • ARRAY_PREPEND function
  • ARRAY_REMOVE function
  • ARRAY_REPLACE function
  • ARRAY_TO_STRING function
  • ARRAY_UPPER function
  • STRING_TO_ARRAY function
  • UNNEST function

Last update on August 19 2022 21:51:31 (UTC/GMT +8 hours)

UNNEST() function

This function is used to expand an array to a set of rows.

Syntax:

unnest(anyarray)

Return Type:

setof anyelement

PostgreSQL Version: 9.3

Example: PostgreSQL UNNEST() function

Code:

SELECT unnest(ARRAY[1,2]);

Sample Output:

unnest -------- 1 2 (2 rows)

Previous: STRING_TO_ARRAY function
Next: Introduction to JOIN

  • Exercises: Weekly Top 12 Most Popular Topics
  • Pandas DataFrame: Exercises, Practice, Solution
  • Conversion Tools
  • JavaScript: HTML Form Validation
  • SQL Exercises, Practice, Solution - SUBQUERIES
  • C Programming Exercises, Practice, Solution : For Loop
  • Python Exercises, Practice, Solution
  • Python Data Type: List - Exercises, Practice, Solution
  • C++ Basic: Exercises, Practice, Solution
  • SQL Exercises, Practice, Solution - exercises on Employee Database
  • SQL Exercises, Practice, Solution - exercises on Movie Database
  • SQL Exercises, Practice, Solution - exercises on Soccer Database
  • C Programming Exercises, Practice, Solution : Recursion


What is Ordinality in PostgreSQL?

Use WITH ORDINALITY for set-returning functions: When a function in the FROM clause is suffixed by WITH ORDINALITY , a bigint column is appended to the output which starts from 1 and increments by 1 for each row of the function's output. This is most useful in the case of set returning functions such as unnest() .

What does Unnest function do?

The UNNEST function returns a result table that includes a row for each element of the specified array. If there are multiple ordinary array arguments specified, the number of rows will match the array with the largest cardinality.

What is Unnest?

: to put out of or as if out of a nest.

How does cross join Unnest work?

A cross join will take every individual element of your unnested array and join it back to its parent row. This will create multiple rows for each element of your array but you can then filter it down.