here is comprehensive example:
t=# with i ( name, url, created_at, updated_at, file_name, is_main ) as
(VALUES
( 'warrior_workout_1','https://example.com/upload1.pdf', now(), now(), 'upload1.pdf', TRUE ),
( 'warrior_workout_2','https://example.com/upload2.pdf', now(), now(), 'upload2.pdf', TRUE ),
( 'warrior_workout_3','https://example.com/upload3.pdf', now(), now(), 'upload3.pdf', TRUE ))
select gs,i.* from i
join generate_series(1,4) gs on true order by gs, name;
gs | name | url | created_at | updated_at | file_name | is_main
----+-------------------+---------------------------------+-------------------------------+-------------------------------+-------------+---------
1 | warrior_workout_1 | https://example.com/upload1.pdf | 2018-02-12 22:25:18.142185+00 | 2018-02-12 22:25:18.142185+00 | upload1.pdf | t
1 | warrior_workout_2 | https://example.com/upload2.pdf | 2018-02-12 22:25:18.142185+00 | 2018-02-12 22:25:18.142185+00 | upload2.pdf | t
1 | warrior_workout_3 | https://example.com/upload3.pdf | 2018-02-12 22:25:18.142185+00 | 2018-02-12 22:25:18.142185+00 | upload3.pdf | t
2 | warrior_workout_1 | https://example.com/upload1.pdf | 2018-02-12 22:25:18.142185+00 | 2018-02-12 22:25:18.142185+00 | upload1.pdf | t
2 | warrior_workout_2 | https://example.com/upload2.pdf | 2018-02-12 22:25:18.142185+00 | 2018-02-12 22:25:18.142185+00 | upload2.pdf | t
2 | warrior_workout_3 | https://example.com/upload3.pdf | 2018-02-12 22:25:18.142185+00 | 2018-02-12 22:25:18.142185+00 | upload3.pdf | t
3 | warrior_workout_1 | https://example.com/upload1.pdf | 2018-02-12 22:25:18.142185+00 | 2018-02-12 22:25:18.142185+00 | upload1.pdf | t
3 | warrior_workout_2 | https://example.com/upload2.pdf | 2018-02-12 22:25:18.142185+00 | 2018-02-12 22:25:18.142185+00 | upload2.pdf | t
3 | warrior_workout_3 | https://example.com/upload3.pdf | 2018-02-12 22:25:18.142185+00 | 2018-02-12 22:25:18.142185+00 | upload3.pdf | t
4 | warrior_workout_1 | https://example.com/upload1.pdf | 2018-02-12 22:25:18.142185+00 | 2018-02-12 22:25:18.142185+00 | upload1.pdf | t
4 | warrior_workout_2 | https://example.com/upload2.pdf | 2018-02-12 22:25:18.142185+00 | 2018-02-12 22:25:18.142185+00 | upload2.pdf | t
4 | warrior_workout_3 | https://example.com/upload3.pdf | 2018-02-12 22:25:18.142185+00 | 2018-02-12 22:25:18.142185+00 | upload3.pdf | t
(12 rows)
so you need to:
with i ( name, url, created_at, updated_at, file_name, is_main ) as
(VALUES
( 'warrior_workout_1','https://example.com/upload1.pdf', now(), now(), 'upload1.pdf', TRUE ),
( 'warrior_workout_2','https://example.com/upload2.pdf', now(), now(), 'upload2.pdf', TRUE ),
( 'warrior_workout_3','https://example.com/upload3.pdf', now(), now(), 'upload3.pdf', TRUE ))
, s as (
SELECT orders.id
FROM orders
LEFT JOIN uploads
ON uploads.order = orders.id
WHERE uploads.order IS NULL
AND orders.product_type = 'warrior_workout'
)
insert into uploads
select id,i.*
from i
join s on true
order by id,name;