Bird
0
0

You want to create a domain us_state_code that accepts only two uppercase letters representing US states. Which domain definition is correct?

hard📝 Application Q8 of 15
PostgreSQL - Advanced Features
You want to create a domain us_state_code that accepts only two uppercase letters representing US states. Which domain definition is correct?
ACREATE DOMAIN us_state_code AS char(2) CHECK (VALUE ~ '^[A-Z]{3}$');
BCREATE DOMAIN us_state_code AS varchar(2) CHECK (VALUE ~ '^[a-z]{2}$');
CCREATE DOMAIN us_state_code AS char(2) CHECK (VALUE ~ '^[A-Z]{2}$');
DCREATE DOMAIN us_state_code AS varchar(3) CHECK (VALUE ~ '^[A-Z]{2}$');
Step-by-Step Solution
Solution:
  1. Step 1: Determine correct base type and length

    US state codes are exactly two uppercase letters, so char(2) fits best.
  2. Step 2: Verify regex pattern

    The regex '^[A-Z]{2}$' matches exactly two uppercase letters, which is correct.
  3. Final Answer:

    CREATE DOMAIN us_state_code AS char(2) CHECK (VALUE ~ '^[A-Z]{2}$'); -> Option C
  4. Quick Check:

    Domain matches length and uppercase regex [OK]
Quick Trick: Match exact length and case in domain regex [OK]
Common Mistakes:
  • Using lowercase regex
  • Wrong length in char/varchar
  • Mismatch between regex and type length

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes