UNPIVOT. UNNEST( ARRAY[ ] )
UNNEST function serve to transform data from a \u201Cwide\u201D format to a \u201Clong\u201D format\n\n\n\n\nPostgreSQL does not have a built-in UNPIVOT functio
#### `UNNEST` function serve to transform data from a \u201Cwide\u201D format to a \u201Clong\u201D format\n\n\n![image.png](https://assets.leetcode.com/users/images/0336d837-ab7e-4f96-b148-e08634247306_1714376571.187945.png)\n\n**PostgreSQL does not have a built-in UNPIVOT function** like Oracle or SQL Server\n\n---\n\n1 column: `UNNEST(c)`\n\\> 1: `UNNEST(ARRAY[c1, c2, c3])`\n\n# Code\n```\nSELECT \n    product_id, \n    store,\n    price\nFROM (\n  SELECT \n    product_id, \n    UNNEST(ARRAY[\'store1\', \'store2\', \'store3\']) AS store,\n    UNNEST(ARRAY[store1, store2, store3]) AS price\n  FROM \n    Products\n) AS unpivot\nWHERE price IS NOT NULL\n\n```\n> `UNNEST(ARRAY[\'store1\', \'store2\', \'store3\'])`\nIt can be also like `[\'Store1\', \'Store22\', \'Store333\']`, because it\'s just a list of names of the further "melted" columns (`ARRAY[store1, store2, store3]`)\n
['Database', 'PostgreSQL']