0
0
PostgreSQLquery~5 mins

UUID type and generation in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Atext
Bvarchar
Cint
Duuid
Which function generates a random UUID (version 4) in PostgreSQL?
Auuid_generate_v1()
Bgen_random_uuid()
Cuuid_generate_v3()
Drandom_uuid()
What must you do before using gen_random_uuid() in PostgreSQL?
AEnable the <code>pgcrypto</code> extension
BNothing, it works by default
CEnable the <code>uuid-ossp</code> extension
DInstall an external library
Which UUID version includes the MAC address and timestamp?
AVersion 1
BVersion 3
CVersion 4
DVersion 5
Why might you choose UUIDs over serial integers for primary keys?
ASerial integers are harder to generate
BUUIDs are shorter
CUUIDs guarantee global uniqueness without coordination
DUUIDs use less storage space
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.