Further correction of SQL for pg