fix sql syntax for postgresql