• I am all for generating code and the idea of exposing tables as views in a separate schema is a valid one. The problem here is that this code would never pass my code review, far too many issues there. Principally, one should separate the code generation and the execution of the code, that way, this can easily be written as an inline table valued function.
    😎

    Further, there are no comments notifying that the view is generated by code and changes made will potentially be lost.