With just a little bit of imagination, you can build a very powerful domain-specific language on top of a SQL dialect. There is nothing that says your new SQL functions have to be free from side effects either.
You can also do some crazy stuff with recursive SQL evaluation. I.e. a UDF that executes raw SQL command text, which itself can contain the same invocation. Bonus points if this command text resides in the same database and can reflect/edit itself at runtime...