Fix error derailing sql queries