Reviewed code to avoid some problems with PostgreSQL (patch reported by UPCnet)