I have same problem. Have header table which contains only id generated by sequence. I need insert rows into snapshot table and of course i must first fill header. So i have temporary table with many rows and want insert fast to both table.
Loop is easy to write, but its not a way to optimize query (In actualization process it run several thousand times on diferent databases/schemes)
Could run insert with specific values
INSERT INTO csh33 (id)
SELECT (SELECT last_value FROM csh33_id_seq) + row_number() OVER ()
FROM temp_tss11;
-- Primary key "id" is Serial so dont name it
INSERT INTO css33 (header_id, time_from, time_to, code, name)
SELECT (SELECT last_value FROM csh33_id_seq) + row_number() OVER (), now(), null, code, name, FROM temp_tss11;
SELECT setval('csh33_id_seq', (SELECT max(id) FROM csh33) + 1);
Or i could don't name fields with default values
INSERT INTO csh33 SELECT FROM temp_tss11;
-- But must consider raised sequence in filling snapshot table (Don't care about ordering, so only subtract)
INSERT INTO css33 (header_id, time_from, time_to, code, name)
SELECT (SELECT last_value FROM csh33_id_seq) - row_number() OVER (), now(), null, code, name, FROM temp_tss11;
But for you question
INSERT INTO yourTableName SELECT generate_series(1,100)
Note i use PG 9.4