SQL can do anything as of recursive CTEs and application-defined functions with side-effects. Performance and ergonomics are the only remaining concerns.