Created
July 9, 2012 16:09
-
-
Save mmalmeida/3077365 to your computer and use it in GitHub Desktop.
Postgresql complex insert into attempt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| WITH old_models AS( | |
| SELECT car.id,car.code, cc.color_id | |
| FROM car inner join car_color cc ON car.id=cc.car_id | |
| ),new_models AS( | |
| SELECT car.id | |
| FROM car left outer join car_color cc ON car.id=cc.car_id WHERE cc.id IS NULL | |
| ) | |
| INSERT INTO car_color(id,car_id,color_id) | |
| VALUES(nextval('id_sequence'),SELECT car_id FROM new_models, SELECT color_id FROM old_models); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment