Fix some postgres SQL