title: PostgreSQL: Select one of two fields depending on which is empty
body: <p>Hello I have a query where I want to select the value of one of two fields depending if one is empty.</p>
  
  <pre><code>field1 and field2
  </code></pre>
  
  <p>I want to select them as <code>complete_field</code></p>
  
  <pre><code>IF field1 is empty, then complete_field is field2
  ELSE complete_field is field1
  </code></pre>
  
  <p>In php it would be done like:</p>
  
  <pre><code>$complete_field = $field1 == '' ? $field2 : $field1;
  </code></pre>
  
  <p>How would I do this in PostgreSQL?</p>
  
  <p>I tried:</p>
  
  <pre><code>SELECT
  (IF field1 = '' THEN field2 ELSE field1) AS complete_field
  FROM
  table
  </code></pre>
  
  <p>But it doesnt work.</p>
  
  <p>Please help me :) Thanks</p>