If this is a requirement for your application, I would highly recommend looking into migrating to PostgreSQL 10. The native partitioning methods allow the RETURNING statements to work as you're expecting. There are work-arounds for it out there for 9.6 and earlier, but for the life of your project you would likely be better off getting upgraded to 10 now and starting your development from there.