When it comes to write code you don't need to learn magic spells.
All you need is to take a look outside the window and solve your problem with patterns from the real world.
In this article you learn how to apply per-user encryption to the data you store in Postgres. It is quite easy and it will allow you to guarantee the highest level of security and privacy to your users.