title: Postgresql Syntax error at or near " THEN "
body: <p>I'm trying to create a view in Postgresql , but when I run this code appears this error:</p>
  
  <blockquote>
    <p>syntax error at or near " THEN "</p>
  </blockquote>
  
  <pre><code>CREATE OR REPLACE VIEW VW_MONITOR_DEVICE AS
      SELECT
          P.POSIZIONE_DEVICE_ID AS MONITOR_DEVICE_ID,
          P.VALID AS VALID,
           [...]
          IF (VALID == FALSE THEN 'Valid' ELSE P.REASON_FOR_INVALID) AS DESCRIPTION,
           [...]
      FROM public.TA_POSIZIONI_DEVICE P
      JOIN ...
  </code></pre>
  
  <p>TA_POSIZIONI_DEVICE</p>
  
  <ul>
  <li>VALID (Boolean not null)</li>
  </ul>