title: Write an update query only if a column exists in a mysql table through a bash script file
body: <p>I have a bash script .sh file in which I am accessing a MySQL database that contains a table called &quot;Foo&quot;. I am having trouble with the MySQL syntax to perform an update query to set the value in column &quot;Bar&quot; only if &quot;Bar&quot; exists in table &quot;Foo&quot; and else, update values in other columns in &quot;Foo&quot; without column &quot;Bar&quot;. The if/else statement is fed through a wrapper that accesses MySQL command line interface and the update query itself I already have.</p>
  <p>I would like to avoid creating a procedure or a function if possible.</p>
  <p>Right now, the if/else looks like this:</p>
  <pre><code>   IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='Foo' AND 
     column_name='Bar') THEN
         //UPDATE Foo SET Bar query
     ELSE
        //UPDATE Foo without column Bar
     END IF;
  </code></pre>
  <p>I have been searching for hours but still am running into a Query Error of:</p>
  <pre><code>Query Error: Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='Foo' AN' at line 1
  </code></pre>