Challenge - 5 Problems
PostgreSQL CREATE TABLE Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the output of this CREATE TABLE statement?
Consider the following SQL statement in PostgreSQL:
What is the data type of the
CREATE TABLE employees (
id SERIAL PRIMARY KEY,
name VARCHAR(50) NOT NULL,
salary NUMERIC(10,2),
hired_on DATE
);
What is the data type of the
id column after table creation?PostgreSQL
CREATE TABLE employees ( id SERIAL PRIMARY KEY, name VARCHAR(50) NOT NULL, salary NUMERIC(10,2), hired_on DATE );
Attempts:
2 left
💡 Hint
Remember that SERIAL is a shorthand for an integer column that auto-increments.
✗ Incorrect
In PostgreSQL, SERIAL is a pseudo-type that creates an integer column with auto-incrementing behavior using a sequence. So the 'id' column becomes an INTEGER with auto-increment.
❓ query_result
intermediate2:00remaining
What is the maximum length of the 'description' column?
Given this table creation:
What is the maximum length allowed for the
CREATE TABLE products (
product_id UUID PRIMARY KEY,
description TEXT,
price MONEY
);
What is the maximum length allowed for the
description column?PostgreSQL
CREATE TABLE products ( product_id UUID PRIMARY KEY, description TEXT, price MONEY );
Attempts:
2 left
💡 Hint
TEXT type in PostgreSQL can store very large strings.
✗ Incorrect
The TEXT data type in PostgreSQL can store strings of any length, limited only by the maximum size of a field in the database system.
📝 Syntax
advanced2:00remaining
Which CREATE TABLE statement is syntactically correct for a JSONB column?
Choose the correct PostgreSQL CREATE TABLE statement that defines a column named
data with JSONB type:Attempts:
2 left
💡 Hint
Check the spelling and syntax of the NOT NULL constraint.
✗ Incorrect
Option A uses the correct JSONB type and the correct NOT NULL syntax. Other options have syntax errors or invalid keywords.
❓ optimization
advanced2:00remaining
Which data type is best for storing a US phone number in PostgreSQL?
You want to store US phone numbers in a PostgreSQL table. Which data type is the most appropriate for efficient storage and querying?
Attempts:
2 left
💡 Hint
Consider storage size and ability to perform numeric comparisons.
✗ Incorrect
BIGINT stores numeric digits efficiently and allows numeric operations. VARCHAR or TEXT store strings but use more space and are slower for numeric queries.
🧠 Conceptual
expert2:00remaining
What happens if you define a column as SERIAL and also specify a default value?
In PostgreSQL, consider this table definition:
What will be the behavior of the
CREATE TABLE test (
id SERIAL DEFAULT 1000 PRIMARY KEY
);
What will be the behavior of the
id column when inserting rows without specifying id?Attempts:
2 left
💡 Hint
Think about how DEFAULT interacts with SERIAL's implicit sequence.
✗ Incorrect
Specifying DEFAULT 1000 overrides the implicit sequence default created by SERIAL, so all inserts without id use 1000, causing duplicate key errors if multiple rows inserted.