I came across a project for time based UUID ("tuid") a little while back: https://github.com/tanglebones/pg_tuid
I haven't used in production but skimmed through the code a bit out of technical curiosity. It handles some of the expected edge cases for backwards clock drift and concurrent generation. The repo includes a PG extension and sample app code for generating tuids in a couple languages as well as a pure-SQL one (though that one uses random() rather than get_random_bytes() so I'd consider it more of an proof of concept). Regards, -- Sehrope Sarkuni Founder & CEO | JackDB, Inc. | https://www.jackdb.com/