Syntax error on declaring a variable inside a transaction
Try using a declare block before the main block:

DECLARE
  -- declarations go here
BEGIN
  -- commands go here
END;


If you need this as an anonymous block (not in any function, etc.) also read about DO.