Re: insert into table from list or array ?

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: Andreas <maps(dot)on(at)gmx(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: insert into table from list or array ?
Date: 2010-10-18 18:14:28
Message-ID: AANLkTimxaYzBmm9PyLXgf9okbLmM0eYTMQmgU1kpTZNr@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello

2010/10/18 Andreas <maps(dot)on(at)gmx(dot)net>:
>  Hi,
>
> is it possible to insert into a table from list or an array ?
>

yes, it's possible

INSERT INTO tmptab
SELECT v
FROM unnest(string_to_array('1,2,4,2,1',',')) g(v)

Regards

Pavel Stehule

> Suppose there is a set of numbers that might be IDs of tables within the DB.
> To work with them I'd need a temporary table that just holds a single column
> with those numbers.
> Something like
>
> create temporary table tmptable as select id from
> ( 2, 3, 5, 7, 11, 13, 17, 19, 23, 31,
>  37, ... );
>
> would be great.
>
> I get those numbers as textfile with 10 numbers per line and devided by
> comma+space as in the sample above, though the comma+space is negotiable if
> this were an issue.
>
> :)
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas 2010-10-18 23:05:02 Re: insert into table from list or array ?
Previous Message Viktor Bojović 2010-10-18 18:12:56 Re: insert into table from list or array ?