Create A Custom Prefix On A UUID

- 1 answer

I would like to know if there is any way to create a custom prefix on UUID's in rails. I would like to generate something like:


I found this code, which I can add to my migration to create the UUID:

t.uuid "uuid", default: "uuid_generate_v4()"

But this would generate something like:


Is it possible to get the format that I want?



As mentioned in comments, postgres defines the UUID as (

A sequence of lower-case hexadecimal digits, in several groups separated by 
hyphens, specifically a group of 8 digits followed by three groups of 4 digits 
followed by a group of 12 digits, for a total of 32 digits representing the 128 bits

So you can't prefix ret_ in UUID column. Also you shouldn't, if you want to identify retailer and customer create another column for it.

SqlFiddle when concatenated UUID is used. It'll throw an error.