Finite-State Machines with recursive SQL