I have the same problem. It has a header table that contains only the identifier generated by the sequence. I need to insert rows into the snapshot table, and of course I have to fill in the title first. So I have a temporary table with many rows and want to quickly insert into both tables.
Loop is easy to write, but this is not a way to optimize the query (during the update process, it starts several thousand times on different databases / schemas)
May trigger insertion with specific values
INSERT INTO csh33 (id) SELECT (SELECT last_value FROM csh33_id_seq) + row_number() OVER () FROM temp_tss11;
Or I canβt name the fields with default values
INSERT INTO csh33 SELECT FROM temp_tss11;
But the question is for you
INSERT INTO yourTableName SELECT generate_series(1,100)
Note: I am using PG 9.4
source share