Sample Header Ad - 728x90

Unnest array of arrays

5 votes
1 answer
4247 views
In my parameterized query I have to unnest arrays with 1 dimension and 2 dimensions:
$1: ARRAY['id1', 'id2']
$2: ARRAY[ARRAY['tag1'], ARRAY['tag2']]
I tried this query:
INSERT INTO table (id, tags)
SELECT * FROM UNNEST ($1::text[], $2::text[][])
But got this error: > column "tags" is of type text[] but expression is of type text I want the result of SELECT * FROM UNNEST ... to be 2 rows:
'id1', ARRAY['tag1']
'id2', ARRAY['tag2']
Asked by pietrushka (51 rep)
Jan 24, 2022, 08:30 PM
Last activity: Jul 24, 2025, 12:26 AM