0
0
PostgreSQLquery~20 mins

UUID type and generation in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
UUID Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of this UUID generation query?
Consider the following PostgreSQL query that generates a UUID using the gen_random_uuid() function. What is the expected output type of the query?
PostgreSQL
SELECT gen_random_uuid();
AA single row with a random integer value
BMultiple rows each containing a UUID value
CA single row with a UUID value in standard 8-4-4-4-12 hexadecimal format
DAn error because <code>gen_random_uuid()</code> is not a valid function
Attempts:
2 left
💡 Hint
Think about what gen_random_uuid() returns and how many rows the query produces.
🧠 Conceptual
intermediate
2:00remaining
Which UUID version does gen_random_uuid() generate?
In PostgreSQL, the gen_random_uuid() function generates UUIDs. Which version of UUID does it produce?
AVersion 4 (randomly generated UUID)
BVersion 3 (name-based using MD5)
CVersion 1 (time-based UUID)
DVersion 5 (name-based using SHA-1)
Attempts:
2 left
💡 Hint
Consider the randomness aspect of the UUID generated by gen_random_uuid().
📝 Syntax
advanced
2:30remaining
Which query correctly creates a table with a UUID primary key that auto-generates UUIDs?
You want to create a PostgreSQL table named users with a user_id column as a UUID primary key that automatically generates a UUID for each new row. Which query is correct?
ACREATE TABLE users (user_id UUID PRIMARY KEY DEFAULT gen_random_uuid());
BCREATE TABLE users (user_id UUID PRIMARY KEY DEFAULT uuid_generate_v4());
CCREATE TABLE users (user_id UUID PRIMARY KEY DEFAULT random_uuid());
DCREATE TABLE users (user_id UUID PRIMARY KEY DEFAULT uuid());
Attempts:
2 left
💡 Hint
Check the exact function name for generating random UUIDs in PostgreSQL's pgcrypto extension.
optimization
advanced
2:30remaining
Which approach improves UUID indexing performance in PostgreSQL?
You have a table with a UUID primary key generated by gen_random_uuid(). UUIDs are random and can cause index bloat. Which approach can improve index performance?
ADisable indexing on the UUID column
BUse UUID version 1 (time-based) instead of version 4 to generate UUIDs
CStore UUIDs as text instead of UUID type
DCreate a B-tree index on the UUID column without changes
Attempts:
2 left
💡 Hint
Think about how the order of UUID values affects index performance.
🔧 Debug
expert
3:00remaining
Why does this query fail with "function gen_random_uuid() does not exist" error?
You run this query: SELECT gen_random_uuid(); but get the error: function gen_random_uuid() does not exist. What is the most likely cause?
AThe query requires superuser privileges to run
BThe function name is misspelled; it should be <code>generate_random_uuid()</code>
CThe UUID type is not supported in this PostgreSQL version
DThe pgcrypto extension is not installed or enabled in the database
Attempts:
2 left
💡 Hint
Check if the required extension for UUID generation is available and enabled.