The problem was that the 'position count' for a statement was inaccurate because of mismatch between windows linebreaks and unix linebreaks (rn versus n). This was fixed with the formatter like this (formatter inserted unix linebreaks between statements).
Maybe the templates use unix-linebreaks (they are probably copied from some MySQL resource) and that could explain why it still occurs when inserting from templates. We will check!