At the first look its seems correct to me but Postgresql was refusing it at every attempt. After studying the complete code with keen detail , I got to know about the actual bug When SQLAlchemy ...
Some results have been hidden because they may be inaccessible to you
Show inaccessible results