Re: Use multidimensional array as VALUES clause in insert - Mailing list pgsql-sql

From Thomas Kellerer
Subject Re: Use multidimensional array as VALUES clause in insert
Date
Msg-id 060a1d9c-ff92-01eb-a0d8-c6370c854b13@gmx.net
Whole thread Raw
In response to Use multidimensional array as VALUES clause in insert  (Mike Martin <redtux1@gmail.com>)
Responses Re: Use multidimensional array as VALUES clause in insert  (Mike Martin <redtux1@gmail.com>)
List pgsql-sql
Mike Martin schrieb am 11.08.2020 um 12:50:
> Is this possible? I have seen examples with array literals as VALUES string, but I cant seen to get it to work with
anactual array. 
>
> testing code
>
> --This gets me a multidimensional array
> with arr AS (
> SELECT ARRAY(SELECT ARRAY[fileid::text,tagname,array_to_string(tagvalue,E'\b')]
> FROM tagdata_all) -- limit 100)
> arr1
> )
> --Then
>
> INSERT INTO  tagdatatest2
> SELECT  arr1::text[] FROM arr --doesnt work only populates one column with original array

I don't understand why you aggregate in the first place if you want to the insert the array elements as rows.

Can't you just do:

   INSERT INTO  tagdatatest2 (fileid, tagname, tagvalue)
   SELECT fileid, tagname, array_to_string(tagvalue,E'\b')
   FROM tagdata_all




pgsql-sql by date:

Previous
From: "David G. Johnston"
Date:
Subject: Re: Use multidimensional array as VALUES clause in insert
Next
From: Igor Andriychuk
Date:
Subject: Re: Use multidimensional array as VALUES clause in insert