Fixed SQL syntax for postgresql