As an alternative to the INSERT ... RETURNING clause mentioned by Cody, you can use the current value for the sequence associated with the ID column:
BEGIN; INSERT INTO albums [...]; INSERT INTO album_images (currval('albums_id_seq'), image_id) [...]; COMMIT;
This assumes a standard Postgres naming scheme when creating a sequence automatically for columns defined as serial .
Another alternative - if you use only one insertion, is to use the lastval() function. Then you would not even need to put the sequence name in the INSERT statement:
BEGIN; INSERT INTO albums [...]; INSERT INTO album_images (lastval(), image_id) [...]; COMMIT;
source share