At the moment there is no way of doing conditional expressions in SQL. Having at least the CASE statement and COALESCE as described here https://www.postgresql.org/docs/9.4/static/functions-conditional.html would be of great help.