0
0
PostgreSQLquery~10 mins

Domain types for validation in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a domain named 'positive_int' that only allows integers greater than zero.

PostgreSQL
CREATE DOMAIN positive_int AS INTEGER CHECK (VALUE [1] 0);
Drag options to blanks, or click blank then click option'
A=
B>
C<
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' causes the domain to accept only negative numbers.
Using '=' restricts the domain to only zero, not positive numbers.
2fill in blank
medium

Complete the code to create a domain 'email_text' that only accepts text containing the '@' character.

PostgreSQL
CREATE DOMAIN email_text AS TEXT CHECK (POSITION('[1]' IN VALUE) > 0);
Drag options to blanks, or click blank then click option'
A%
B#
C$
D@
Attempts:
3 left
💡 Hint
Common Mistakes
Using '#' or '$' will not correctly validate email addresses.
Forgetting to check the position > 0 means the character might not be present.
3fill in blank
hard

Fix the error in the domain creation that should restrict a phone number to exactly 10 digits.

PostgreSQL
CREATE DOMAIN phone_number AS TEXT CHECK (LENGTH(VALUE) [1] 10);
Drag options to blanks, or click blank then click option'
A=
B>
C<>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' or '<' allows lengths other than 10.
Using '<>' means not equal, which is the opposite of the requirement.
4fill in blank
hard

Fill both blanks to create a domain 'rating' that accepts integers between 1 and 5 inclusive.

PostgreSQL
CREATE DOMAIN rating AS INTEGER CHECK (VALUE [1] 1 AND VALUE [2] 5);
Drag options to blanks, or click blank then click option'
A>=
B<
C<=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' or '<' excludes the boundary values 1 or 5.
Using '=' alone only allows one value, not a range.
5fill in blank
hard

Fill all three blanks to create a domain 'zipcode' that accepts exactly 5 digits and only numeric characters.

PostgreSQL
CREATE DOMAIN zipcode AS TEXT CHECK (LENGTH(VALUE) [1] 5 AND VALUE ~ '[2]' AND VALUE !~ '[3]');
Drag options to blanks, or click blank then click option'
A=
B^[0-9]{5}$
C[^0-9]
D!=
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect regex patterns that allow letters or symbols.
Using '!=' instead of regex operators for pattern matching.