separate user for the frontend and the wallet #25

Hmm... That can work for some functions, but not all. It won't work for functions that do inserts. The reason I did it the same way everywhere is so that we can easily keep track of which functions do or don't accept uid 0. If we hide the check in a where clause it's very easy to modify the function later on and accidentally remove this check.

I think this is a language problem. I wish there was a better way to write these functions. This syntax is really difficult to manage/edit when we need to make changes and it's very difficult to read and audit for a human.

What if we create a separate table for uid 0? I think the current design is not very good from a maintainability and security point of view.

Another idea would be to change uid 0 to uid null. Then we can use "RETURNS NULL ON NULL INPUT" to secure all these functions.

Also, is there any benefit of keeping sql instead of just making everything plpgsql? Just cleaner syntax? I was actually considering converting everything to plpgsql so that we don't have two languages in the same file.