Okay, so the title sucks but here is my problem. I have two tables:
image
: which holds some basic meta data and has aautoincrement
primary keyid
imagesize
: which is holds multiple different sizes per image and there S3 url, width, height, etc. and has a foreign key toimage.id
Soimage
forms a one-to-many relationship withimagesize
.
Currently I first create and image with INSERT INTO image ... RETURNING image.id
and then create the sizes with INSERT INTO imagesize ...
where I use the returned id.
Is there a way of combining these two INSERTs so there is no additional roundtrip between my code and the database?