Fix incorrect SQL for PostgreSQL