Select Query With If Condition In Postgresql