Bird
0
0

Given the ENUM type and table:

medium📝 query result Q4 of 15
PostgreSQL - Advanced Features
Given the ENUM type and table:
CREATE TYPE mood AS ENUM ('happy', 'sad', 'neutral');
CREATE TABLE person (name TEXT, current_mood mood);
INSERT INTO person VALUES ('Alice', 'happy'), ('Bob', 'sad');
SELECT * FROM person WHERE current_mood = 'neutral';

What will the SELECT query return?
ARows with persons having mood 'happy' or 'sad'
BRows with all persons, ignoring mood
CError because 'neutral' is not a valid ENUM value
DNo rows, because no person has mood 'neutral'
Step-by-Step Solution
Solution:
  1. Step 1: Understand inserted data

    Only 'happy' and 'sad' moods are inserted; no 'neutral' rows exist.
  2. Step 2: Analyze SELECT query

    Query filters for current_mood = 'neutral', which matches no rows.
  3. Final Answer:

    No rows, because no person has mood 'neutral' -> Option D
  4. Quick Check:

    Query result = empty set when no matching ENUM value rows [OK]
Quick Trick: Query returns no rows if no matching ENUM value exists [OK]
Common Mistakes:
  • Assuming query returns error for valid ENUM value
  • Expecting all rows returned without filter
  • Confusing ENUM values with strings not in ENUM

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes