Question:
Is it possible to convert the following into a two-columned table?SELECT * FROM UNNEST([[1,'a'],[2,'b'], [3,'c']) AS tbl (num,str);
Or more generally into a table of n
columns where n
is the size of the inner array (i.e., the length of a row).The array structure is
arr[rows][cols]
Answer:
Arrays in PostgreSQL can contain elements of one type (but it can be composite type). So array likearray[1,2,'e']
is invalid in PostgreSQL.What can be done is to unnest two arrays in one statement
SELECT UNNEST(array[1,2,3]),unnest(array['a','b','c'])
If you have better answer, please add a comment about this, thank you!