IIF Function - SQL Server to PostgreSQL Migration

In SQL Server, the IIF function returns an expression based on the condition. In PostreSQL, you can use the CASE expression.

SQL Server:

  -- If condition is true return the first expression, otherwise return the second expression
  SELECT IIF(2 > 1, 'Yes', 'No')
  # Yes

PostgreSQL:

  -- If condition is true return the first expression, otherwise return the second expression
  SELECT CASE WHEN 2 > 1 THEN 'Yes' ELSE 'No' END
  # Yes

For more information, see SQL Server to PostgreSQL Migration.