Fix sqlalchemy CompileError

This bug was replicated to mysql database.

Change-Id: If41e76474c29f764898a824ab324889c6cf2e85b
Fixes: bug #1201438
Merge "Fix sqlalchemy CompileError"