Bug Fix:#3789 Erroneous LIMIT clause in prettyprinted SQL

This is Bug Fix:#3789 Erroneous LIMIT clause in prettyprinted SQL
I have tested only for several testcases.Check more.