SQL

Write an awesome doc for SQL. A very nice and practical one, extracted from SQL official documentation.

View on GitHub

unnest – Array Function

unnest

Good for

Normalizing denormalized data, where each array element needs to be processed individually.

Considerations

Example – Bulk create

INSERT INTO users(id, name)
SELECT *
FROM unnest(
  $1::uuid[],
  $2::text[]
) a(id, name)

[!NOTE]

The simplified version of the nested SELECT query:

SELECT * FROM unnest(Array[1, 2], Array['はると', 'Kasir']) a(id, name)