Challenge - 5 Problems
UUID Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2: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();Attempts:
2 left
💡 Hint
Think about what
gen_random_uuid() returns and how many rows the query produces.✗ Incorrect
The gen_random_uuid() function returns a single UUID value in the standard format as a single row result.
🧠 Conceptual
intermediate2: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?Attempts:
2 left
💡 Hint
Consider the randomness aspect of the UUID generated by
gen_random_uuid().✗ Incorrect
gen_random_uuid() generates a Version 4 UUID, which is randomly generated.
📝 Syntax
advanced2: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?Attempts:
2 left
💡 Hint
Check the exact function name for generating random UUIDs in PostgreSQL's pgcrypto extension.
✗ Incorrect
The correct function to generate random UUIDs in PostgreSQL's pgcrypto extension is gen_random_uuid(). The other functions either do not exist or are incorrect.
❓ optimization
advanced2: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?Attempts:
2 left
💡 Hint
Think about how the order of UUID values affects index performance.
✗ Incorrect
UUID version 1 includes a timestamp, so values are roughly ordered, reducing index fragmentation and improving performance compared to random UUIDs.
🔧 Debug
expert3: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?Attempts:
2 left
💡 Hint
Check if the required extension for UUID generation is available and enabled.
✗ Incorrect
The gen_random_uuid() function is provided by the pgcrypto extension. If this extension is not installed or enabled, the function will not exist.