PostgreSQL: Select one of two fields depending on which is empty
Use CASE WHEN .. THEN .. ELSE .. END
, e.g.:
SELECT (CASE WHEN (field1 IS NULL OR field1 = '') THEN field2 ELSE field1 END)FROM table;
Check it out at the official docs.
The ANSI SQL function Coalesce() is what you want.
select Coalesce(field1,field2) from table;