I forgot to mention that i was creating a view just before this i.e sql="create view %s as %s" % (foldername, query) # self.cursor.execute(sql) self.cursor.execute(sql) Now if i remove this, the insert code works fine. Regards Saptarshi