A user defined function could be used.
Related (I know this isn't your question): Please note if you have a lot of rows in the table (millions of rows), and if you have an index on this UUID, you should avoid randomly distributed UUIDs for performance reasons. This is for all databases, except if it the index easily fits completely in memory. Because of that, I personally would avoid UUIDs and use sequences instead if ever possible.