0
0
PostgreSQLquery~20 mins

ENUM types in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
ENUM 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 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;
A[{"id":1,"name":"Alice","current_mood":"happy"}]
BSyntaxError: ENUM type not recognized
CError: invalid input value for enum mood
D[{"id":1,"name":"Alice","current_mood":null}]
Attempts:
2 left
💡 Hint
Remember ENUM values must be one of the predefined set.
🧠 Conceptual
intermediate
1:30remaining
Which statement about ENUM types in PostgreSQL is true?
Choose the correct statement about ENUM types in PostgreSQL.
AENUM types can be altered to add new values anywhere in the list without restrictions.
BENUM types allow any string value without restrictions once created.
CENUM types store values as integers internally and enforce allowed values.
DENUM types are not supported in PostgreSQL.
Attempts:
2 left
💡 Hint
Think about how ENUM restricts values and stores them.
📝 Syntax
advanced
2: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?
AALTER TYPE mood ADD VALUE 'excited';
BALTER ENUM mood ADD 'excited';
CALTER TYPE mood ADD 'excited' AFTER 'happy';
DALTER TYPE mood ADD VALUE 'excited' AFTER 'happy';
Attempts:
2 left
💡 Hint
Check the exact syntax for adding a value at a specific position.
optimization
advanced
1: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?
AENUM types use less storage and improve query performance by storing values as integers internally.
BENUM types allow any string value, so they are more flexible than VARCHAR.
CENUM types automatically index the column without extra commands.
DENUM types do not enforce value restrictions, making inserts faster.
Attempts:
2 left
💡 Hint
Think about storage and validation differences.
🔧 Debug
expert
2: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');
ASyntax error due to missing quotes around 'completed'.
BError because 'completed' is not a valid value in the ENUM 'status'.
CError because the table 'tasks' does not exist.
DNo error; the row is inserted with 'completed' as status.
Attempts:
2 left
💡 Hint
Check if the inserted value matches the ENUM allowed values.