Fixes some issues with PostgreSQL on couples of queries

Has this condition some meaning?
When stat.name is not null then stat.name else null is equal to just stat.name, isn't it?