For anyone looking for an answer - it is very prosaic and I was able to identify the problem.
The problem is empty line in the middle of the query, which is interpreted as end of query by DBeaver.
So easy fix is:
Harder fix:
Viva la long night, but finally I know why this was happening.