inspired by https://github.com/michelp/pgfsm According to this post, we should prefer JOIN over CASE.