title: Syntax error at or near "IF" PostgreSQL
body: <p>I am trying to use subselect in my code but it gives me an error. I have found a lot of solution but it still does not work:</p>
  
  <p>Here is my code:</p>
  
  <pre><code>BEGIN;
  IF (SELECT COUNT(*) FROM table1 WHERE Z = 'aaaaa') = 0
  
      THEN
      INSERT INTO table2 (X, Y) VALUES ("abc", 7)
  
  END IF;
  END;
  </code></pre>
  
  <p>and error:</p>
  
  <pre><code>ERROR:  syntax error at or near "IF"
  LINE 2: IF (SELECT COUNT(*) FROM table1 WHERE Path = 'aaaaa') = 0
          ^
  
  
  ********** Error **********
  
  ERROR: syntax error at or near "IF"
  SQL state: 42601
  Character: 8
  </code></pre>
  
  <p>Could you help me?</p>