agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Thomas Kellerer <shammat@gmx.net>
To: pgsql-sql@lists.postgresql.org
Subject: Re: Use multidimensional array as VALUES clause in insert
Date: Tue, 11 Aug 2020 16:08:32 +0200
Message-ID: <060a1d9c-ff92-01eb-a0d8-c6370c854b13@gmx.net> (raw)
In-Reply-To: <CAOwYNKYLxdrqzxQu=HGn+Gf+7qzOr8LMUmbnWJXpOw5_W=TVsQ@mail.gmail.com>
References: <CAOwYNKYLxdrqzxQu=HGn+Gf+7qzOr8LMUmbnWJXpOw5_W=TVsQ@mail.gmail.com>
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
view thread (7+ messages) latest in thread
Message-ID: <060a1d9c-ff92-01eb-a0d8-c6370c854b13@gmx.net>
Permalink: ../060a1d9c-ff92-01eb-a0d8-c6370c854b13@gmx.net/
Also on: postgresql.org/message-id/060a1d9c-ff92-01eb-a0d8-c6370c854b13@gmx.net
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: shammat@gmx.net, pgsql-sql@lists.postgresql.org
Subject: Re: Use multidimensional array as VALUES clause in insert
In-Reply-To: <060a1d9c-ff92-01eb-a0d8-c6370c854b13@gmx.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox