Example 1
Expand a list of fruit names into one row each with a position number
Each engine expands the three-element list into one row per element. PostgreSQL's UNNEST(ARRAY[...]) WITH ORDINALITY AS t(elem, ordinality) generates the element value and a 1-based position in one step. MySQL's JSON_TABLE requires a JSON string rather than a native array; FOR ORDINALITY produces the position. SQL Server's OPENJSON returns a key column that is a 0-based string index — CAST([key] AS INT) + 1 converts it to a 1-based integer. SQLite's json_each returns an integer key starting at 0; adding 1 gives the 1-based position. To expand an array stored in a table column rather than a literal, replace the literal with the column reference in UNNEST, JSON_TABLE, OPENJSON, or json_each.
PostgreSQL uses UNNEST with native array syntax. MySQL uses JSON_TABLE with FOR ORDINALITY. SQL Server uses OPENJSON with 0-based key + 1. SQLite uses json_each with 0-based key + 1. All produce the same three rows.