Runtime validate at the database boundary? Isn't it better to just do runtime validation at the api boundary instead? Then any of the types that make it into the database should be mostly guaranteed by TS (and of course, whatever types are enforced by the database schema itself).
What do you use for runtime? I've used pgtyped in the past and it does a good job at taking raw SQL and generating the return types from runtime:
https://github.com/adelsz/pgtyped
Also it allows AI tools in IDEs like Cursor to work a lot more effectivley because they can leverage type/lint errors to make sure suggestions are correct on the first try.