Generate a UUID as PostgreSQL default value

Shawn OY
0x427567
Published in
2 min readFeb 20, 2020

--

Photo by Kevin Ku on Unsplash

As we know, PostgreSQL has a UUID data type, but you cannot generate a UUID as the default value by default, in general, we generate a UUID first and insert the UUID into the database, might it be very bothered?

What if we can automatically generate a UUID as the default value? Sounds cool, and we have two ways to do it.

#0x01 pgcrypto extension

--

--

Full-stack developer, and a technology geek, focused on Golang, AWS and serverless. Follow me on Twitter @0x427567