Re: Use multidimensional array as VALUES clause in insert

From: Mike Martin <redtux1(at)gmail(dot)com>
To: Thomas Kellerer <shammat(at)gmx(dot)net>
Cc: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: Use multidimensional array as VALUES clause in insert
Date: 2020-08-11 20:59:12
Message-ID: CAOwYNKb32PuSqhX_6JP6tbxYpvcDZVL+-hPoOQy8OHTp-jTaVw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

The example isn't what I am doing, its just a test to get multidimensional
array within db for testing import of array from application (perl in this
case)

On Tue, 11 Aug 2020 at 15:08, Thomas Kellerer <shammat(at)gmx(dot)net> wrote:

>
> 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 an actual 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
>
>
>
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Mike Martin 2020-08-16 13:48:16 Weird issue with truncation of values in array with some tables
Previous Message Igor Andriychuk 2020-08-11 14:43:04 Re: Use multidimensional array as VALUES clause in insert