title: Postgres IF on variable
body: <p>I'm in the process of learning postgres, I've already found a work around to this problem but I wanted to ask the community if something like this is even possible, maybe my syntax is just off.</p>
  
  <pre><code>DO $$ BEGIN
      IF :MODIFYBY IS NOT NULL THEN
          UPDATE User SET ModifyBy = :MODIFYBY WHERE UserId = :USERID;
          UPDATE Profile SET ModifyBy = :MODIFYBY WHERE UserId = :USERID;
      END IF;
  END $$;
  </code></pre>
  
  <p>Receiving </p>
  
  <blockquote>
    <p>syntax error at or near ":"</p>
  </blockquote>
  
  <p>as :MODIFYBY is a parameter to this sql.</p>
  
  <p>How can I test if a parameter is null?</p>
  
  <p>Note: Running on PostgreSQL 9.6</p>
  
  <p>Update:</p>
  
  <p>It is possible my terminology is not correct.  The full sql statement is this</p>
  
  <pre><code>BEGIN;
  
      UPDATE User
         SET Email = :EMAIL         
            ,ModifyDate = now() at time zone 'utc'
      WHERE
          UserId = :USERID;
  
      UPDATE Profile
         SET FirstName = :FIRSTNAME          
            ,LastName = :LASTNAME          
            ,ModifyDate = now() at time zone 'utc'
      WHERE
          UserId = :USERID;
  
      DO $$ BEGIN
          IF :MODIFYBY IS NOT NULL THEN
              UPDATE User SET ModifyBy = :MODIFYBY WHERE UserId = :USERID;
              UPDATE Profile SET ModifyBy = :MODIFYBY WHERE UserId = :USERID;
          END IF;
      END $$;
  
  COMMIT;
  </code></pre>
  
  <p>I added the DO $$ BEGIN and END $$; to get the IF statement to work...</p>