fix sql syntax for pgsql