title: PostgreSQL IF-THEN-ELSE control structure
body: <p>Why do I always get the following error from Postgres?</p>
  
  <p><code>syntax error at or near "IF"</code></p>
  
  <p>I read <a href="http://www.postgresql.org/docs/8.3/static/plpgsql-control-structures.html#PLPGSQL-CONDITIONALS" rel="noreferrer">PostgreSQL: Documentation: 8.3: Control Structures</a>. First I tried to execute a difficult query (with subquery), but then I tried to execute a simple one like this:</p>
  
  <pre class="lang-sql prettyprint-override"><code>IF 2 &lt;&gt; 0 THEN select * from users; END IF;
  </code></pre>
  
  <p>The error is still the same. What am I doing wrong?</p>