Q:

How to copy multiple rows belonging to one id, and add to all of the others ids in postgreSQL

So I have table buses with unique IDs and a code:
| bus_id        | code        |
|:--------------|------------:|
| 1             |        A    |   
| 2             |        A    |   
| 3             |        A    | 
| 4             |        B    |  
| 5             |        B    | 

Now for the bus_id I have these images with their ids in another table Images like this:
| image_id(not unique)| image_link | bus_id   | 
|:--------------------|-----------:|---------:|
| 1                   |     aaa.com|         1|   
| 2                   |     aab.com|         1|      
| 3                   |     aac.com|         4|    
| 4                   |     aad.com|         4|    

How can I extend this image table, so that for each bus_id with the same code from the table buses, will create duplicate rows in the table images for all the buses in each bus code. 
So the result I'm looking for with the examples above is: 
| image_id(not unique)| image_link | bus_id   | 
|:--------------------|-----------:|---------:|
| 1                   |     aaa.com|         1|   
| 2                   |     aab.com|         1| 
| 1                   |     aaa.com|         2|   
| 2                   |     aab.com|         2|      
| 1                   |     aaa.com|         3|   
| 2                   |     aab.com|         3|

(As you can see, bus_id 1:3 all have the code A from table buses)
| 3                   |     aac.com|         4|    
| 4                   |     aad.com|         4| 
| 3                   |     aac.com|         5|    
| 4                   |     aad.com|         5|

(As you can see, bus_id 4:5 all have the code B from table buses) 

A:

You can get the images you need to add by generating all images and then filtering out the ones that exist.
I think this does what you want:
select b.bus_id, b.code, ii.image_id
from busses b join
     (select distinct i.image_id, b.code
      from images i join
           busses b
           on i.bus_id = b.bus_id
     ) ii
     on ii.code = b.code left join
     images i
     on i.bus_id = b.bus_id and i.image_id = ii.image_id
where i.image_id is null;

