Skip to content
Advertisement

postgres insert using CTE and use the inersted id in next sub query

I insert a user into the database. Then I need the user id generated to insert into a teamMember table. I am using CTE’s, I read they run concurrently, is it possible to return the id of the inserted users to the next statement?

Advertisement

Answer

You don’t need the left join on users since do_insert is the same table but updated. In your select put do_insert.id instead of t1.id and get rid of the users left join and it should work.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement