Recall & Review
beginner
What is a UUID in PostgreSQL?
A UUID (Universally Unique Identifier) is a 128-bit value used to uniquely identify information without significant risk of duplication. PostgreSQL has a native UUID data type to store these values efficiently.
Click to reveal answer
beginner
How do you generate a version 4 UUID in PostgreSQL?
You can generate a version 4 UUID using the function
gen_random_uuid() from the pgcrypto extension, which creates a random UUID.Click to reveal answer
intermediate
Which PostgreSQL extension must be enabled to use
gen_random_uuid()?The
pgcrypto extension must be enabled using CREATE EXTENSION IF NOT EXISTS pgcrypto; to use gen_random_uuid().Click to reveal answer
intermediate
What is the difference between
uuid_generate_v1() and gen_random_uuid() in PostgreSQL?uuid_generate_v1() creates a time-based UUID including the MAC address, while gen_random_uuid() creates a random UUID (version 4) without using hardware info.Click to reveal answer
beginner
Why use UUIDs instead of serial integers as primary keys?
UUIDs are globally unique and can be generated independently without coordination, which is useful for distributed systems. Serial integers are simpler but can cause conflicts when merging data from multiple sources.
Click to reveal answer
Which PostgreSQL data type is used to store UUIDs?
✗ Incorrect
PostgreSQL has a native
uuid data type specifically designed to store UUID values efficiently.Which function generates a random UUID (version 4) in PostgreSQL?
✗ Incorrect
gen_random_uuid() generates a random version 4 UUID and requires the pgcrypto extension.What must you do before using
gen_random_uuid() in PostgreSQL?✗ Incorrect
You must enable the
pgcrypto extension with CREATE EXTENSION IF NOT EXISTS pgcrypto; to use gen_random_uuid().Which UUID version includes the MAC address and timestamp?
✗ Incorrect
Version 1 UUIDs are time-based and include the MAC address, unlike version 4 which is random.
Why might you choose UUIDs over serial integers for primary keys?
✗ Incorrect
UUIDs can be generated independently anywhere and still remain unique, which is helpful in distributed systems.
Explain how to generate and store a UUID in a PostgreSQL table.
Think about the data type, extension, and function needed.
You got /3 concepts.
Describe the differences between UUID version 1 and version 4 in PostgreSQL.
Consider how each UUID is generated and what info it contains.
You got /3 concepts.