title: Syntax Error declaring variables in MariaDB
body: <p>I have a problem with the following query:</p>
  
  <pre><code>START TRANSACTION;
  INSERT INTO posts
  (
  -- not relevant
  )
  VALUES
  (
  -- insert works as intended
  );
  COMMIT WORK AND CHAIN;
  
  DECLARE @insertId INT; -- this is where i get the syntax error
  SET @insertId = LAST_INSERT_ID();
  
  UPDATE posts
  SET guid = CONCAT('foo.bar?p=', @insertId)
  WHERE id = @insertId;
  
  -- continue to work with the variable
  INSERT INTO postmeta(post_id, key, value)
  VALUES
  (@insertId, ..., ...),
  (@insertId, ..., ...),
  (@insertId, ..., ...),
  (@insertId, ..., ...);
  COMMIT WORK;
  </code></pre>
  
  <p>Basically I insert a row, and need to update it, using the auto incremented id <strong>immediately</strong> after the insert (to make sure I get the correct value out of the function LAST_INSERT_ID).
  Then I need to fill an other table, also using the auto incremented id. In this use case I figured, that I need to store the value in a variable.
  Why do i get the following error message?
  "You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DECLARE @insertId INT; SET @insertId = LAST_INSERT_ID();' at line 1"
  Is the problem that I don't create a procedure or user defined function?</p>