pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedinsert into table from list or array ?
4+ messages / 3 participants
[nested] [flat]
* insert into table from list or array ?
@ 2010-10-18 18:00 Andreas <maps.on@gmx.net>
2010-10-18 18:12 ` Re: insert into table from list or array ? Viktor Bojović <viktor.bojovic@gmail.com>
2010-10-18 18:14 ` Re: insert into table from list or array ? Pavel Stehule <pavel.stehule@gmail.com>
0 siblings, 2 replies; 4+ messages in thread
From: Andreas @ 2010-10-18 18:00 UTC (permalink / raw)
To: pgsql-sql
Hi,
is it possible to insert into a table from list or an array ?
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.
:)
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: insert into table from list or array ?
2010-10-18 18:00 insert into table from list or array ? Andreas <maps.on@gmx.net>
@ 2010-10-18 18:12 ` Viktor Bojović <viktor.bojovic@gmail.com>
1 sibling, 0 replies; 4+ messages in thread
From: Viktor Bojović @ 2010-10-18 18:12 UTC (permalink / raw)
To: Andreas <maps.on@gmx.net>; +Cc: pgsql-sql
i think that you can try to
create temporary table tmptable(id integer, numbers integer[]);
and
insert into table values (1,array[2, 3, 5, 7, 11, 13, 17, 19, 23, 31, 37,
...]);
On Mon, Oct 18, 2010 at 8:00 PM, Andreas <maps.on@gmx.net> wrote:
> Hi,
>
> is it possible to insert into a table from list or an array ?
>
> 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@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>
--
---------------------------------------
Viktor Bojović
---------------------------------------
Wherever I go, Murphy goes with me
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: insert into table from list or array ?
2010-10-18 18:00 insert into table from list or array ? Andreas <maps.on@gmx.net>
@ 2010-10-18 18:14 ` Pavel Stehule <pavel.stehule@gmail.com>
2010-10-18 23:05 ` Re: insert into table from list or array ? Andreas <maps.on@gmx.net>
1 sibling, 1 reply; 4+ messages in thread
From: Pavel Stehule @ 2010-10-18 18:14 UTC (permalink / raw)
To: Andreas <maps.on@gmx.net>; +Cc: pgsql-sql
Hello
2010/10/18 Andreas <maps.on@gmx.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@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: insert into table from list or array ?
2010-10-18 18:00 insert into table from list or array ? Andreas <maps.on@gmx.net>
2010-10-18 18:14 ` Re: insert into table from list or array ? Pavel Stehule <pavel.stehule@gmail.com>
@ 2010-10-18 23:05 ` Andreas <maps.on@gmx.net>
0 siblings, 0 replies; 4+ messages in thread
From: Andreas @ 2010-10-18 23:05 UTC (permalink / raw)
To: pgsql-sql
Am 18.10.2010 20:14, schrieb Pavel Stehule:
> 2010/10/18 Andreas:
>> 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)
>
Thanks Pavel,
though I'm just not yet 100% aware how it works but it works. :)
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2010-10-18 23:05 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2010-10-18 18:00 insert into table from list or array ? Andreas <maps.on@gmx.net>
2010-10-18 18:12 ` Viktor Bojović <viktor.bojovic@gmail.com>
2010-10-18 18:14 ` Pavel Stehule <pavel.stehule@gmail.com>
2010-10-18 23:05 ` Andreas <maps.on@gmx.net>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox