Generate UUID in PostgreSQL
UUID is an important data type that we can utilize in relational database (RDS). There are two common ways to generate UUIDs in PostgreSQL: using the uuid-ossp
extension or the pgcrypto
extension. In this article, we will discuss how to generate UUIDs using both pgcrypto
.
To use this function, make sure that the pgcrypto
extension is enabled in your database. You can do this by running this command:
CREATE EXTENSION IF NOT EXISTS "pgcrypto";
Let’s say, you have a table named candidate
with a UUID column named id
. You can create the table like this: