IF-THEN-ELSE statements in postgresql

Solution 1:

As stated in PostgreSQL docs here:

The SQL CASE expression is a generic conditional expression, similar to if/else statements in other programming languages.

Code snippet specifically answering your question:

SELECT field1, field2,
  CASE
    WHEN field1>0 THEN field2/field1
    ELSE 0
  END 
  AS field3
FROM test

Solution 2:

case when field1>0 then field2/field1 else 0 end as field3