Challenge - 5 Problems
ENUM 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 ENUM insertion query?
Given the ENUM type
mood with values ('happy', 'sad', 'neutral'), what will be the result of this insertion?PostgreSQL
CREATE TYPE mood AS ENUM ('happy', 'sad', 'neutral'); CREATE TABLE person (id SERIAL PRIMARY KEY, name TEXT, current_mood mood); INSERT INTO person (name, current_mood) VALUES ('Alice', 'happy'); SELECT * FROM person;
Attempts:
2 left
💡 Hint
Remember ENUM values must be one of the predefined set.
✗ Incorrect
The insertion uses a valid ENUM value 'happy', so the row is inserted correctly and returned.
🧠 Conceptual
intermediate1:30remaining
Which statement about ENUM types in PostgreSQL is true?
Choose the correct statement about ENUM types in PostgreSQL.
Attempts:
2 left
💡 Hint
Think about how ENUM restricts values and stores them.
✗ Incorrect
PostgreSQL ENUM types store values as integers but restrict values to the predefined set. Adding new values is possible but only at the end or with specific commands.
📝 Syntax
advanced2:00remaining
Which option correctly adds a new value 'excited' to an existing ENUM type 'mood'?
You have an ENUM type
mood with values ('happy', 'sad', 'neutral'). Which SQL command correctly adds 'excited' as a new value?Attempts:
2 left
💡 Hint
Check the exact syntax for adding a value at a specific position.
✗ Incorrect
The correct syntax to add a new value to an ENUM type at a specific position is: ALTER TYPE mood ADD VALUE 'excited' AFTER 'happy';
❓ optimization
advanced1:30remaining
What is a key advantage of using ENUM types over VARCHAR for fixed sets of values?
Why might you choose an ENUM type instead of VARCHAR for a column with limited possible values?
Attempts:
2 left
💡 Hint
Think about storage and validation differences.
✗ Incorrect
ENUM types store values internally as integers referencing the allowed strings, which can save space and speed up comparisons compared to VARCHAR.
🔧 Debug
expert2:30remaining
Why does this INSERT fail with an error?
Given the ENUM type
status with values ('new', 'in_progress', 'done'), why does this query fail?
INSERT INTO tasks (id, status) VALUES (1, 'completed');PostgreSQL
CREATE TYPE status AS ENUM ('new', 'in_progress', 'done'); CREATE TABLE tasks (id INT PRIMARY KEY, status status); INSERT INTO tasks (id, status) VALUES (1, 'completed');
Attempts:
2 left
💡 Hint
Check if the inserted value matches the ENUM allowed values.
✗ Incorrect
The ENUM type 'status' only allows 'new', 'in_progress', and 'done'. 'completed' is not in the list, so the insert fails with an error.