agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedFrom: Igor Andriychuk <2.andriychuk@gmail.com>
To: Mike Martin <mike@redtux.plus.com>
Cc: pgsql-sql <pgsql-sql@lists.postgresql.org>
Subject: Re: Use multidimensional array as VALUES clause in insert
Date: Tue, 11 Aug 2020 07:43:04 -0700
Message-ID: <AB2B9679-1B23-4354-94DD-2B4AF7538F13@gmail.com> (raw)
In-Reply-To: <CAOwYNKbE7OSDscT5uJX6ruW8XpupmbG9-msrVhqpOhkBYPUVyg@mail.gmail.com>
References: <CAOwYNKbE7OSDscT5uJX6ruW8XpupmbG9-msrVhqpOhkBYPUVyg@mail.gmail.com>
Hi Martin,
May be I don’t understand completely what are you trying to accomplish but based on your example bellow UNNEST function should do a magic for you, this is the example I wrote for your case:
create table if not exists foo(id int, arr text[]);
truncate table foo;
insert into foo values (1, '{"value1", "value2", "value3"}'), (2, '{"value21", "value22", "value23"}');
create table if not exists foo2(id int, val text);
truncate table foo2;
insert into foo2
select id, unnest(arr) from foo;
Is this what you trying to do?
Best,
-Igor
> On Aug 11, 2020, at 3:47 AM, Mike Martin <mike@redtux.plus.com> wrote:
>
> 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
>
view thread (7+ messages) latest in thread
Message-ID: <AB2B9679-1B23-4354-94DD-2B4AF7538F13@gmail.com>
Permalink: ../AB2B9679-1B23-4354-94DD-2B4AF7538F13@gmail.com/
Also on: postgresql.org/message-id/AB2B9679-1B23-4354-94DD-2B4AF7538F13@gmail.com
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: 2.andriychuk@gmail.com, mike@redtux.plus.com, pgsql-sql@lists.postgresql.org
Subject: Re: Use multidimensional array as VALUES clause in insert
In-Reply-To: <AB2B9679-1B23-4354-94DD-2B4AF7538F13@gmail.com>
* 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