0
0
PostgreSQLquery~20 mins

CREATE TABLE with PostgreSQL types - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PostgreSQL CREATE TABLE Master
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 CREATE TABLE statement?
Consider the following SQL statement in PostgreSQL:

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
);
AINTEGER with auto-increment behavior
BVARCHAR with length 50
CNUMERIC with precision 10 and scale 2
DDATE type
Attempts:
2 left
💡 Hint
Remember that SERIAL is a shorthand for an integer column that auto-increments.
query_result
intermediate
2:00remaining
What is the maximum length of the 'description' column?
Given this table creation:

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
);
A1000 characters
B255 characters
C50 characters
DUnlimited length (only limited by system memory)
Attempts:
2 left
💡 Hint
TEXT type in PostgreSQL can store very large strings.
📝 Syntax
advanced
2: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:
ACREATE TABLE logs (id SERIAL PRIMARY KEY, data JSONB NOT NULL);
BCREATE TABLE logs (id SERIAL PRIMARY KEY, data JSON NOTB NULL);
CCREATE TABLE logs (id SERIAL PRIMARY KEY, data JSONB NULLABLE);
DCREATE TABLE logs (id SERIAL PRIMARY KEY, data JSONB NOTNULL);
Attempts:
2 left
💡 Hint
Check the spelling and syntax of the NOT NULL constraint.
optimization
advanced
2: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?
AVARCHAR(14) to store formatted phone numbers like '(123) 456-7890'
BBIGINT to store only digits without formatting
CTEXT to allow any phone number format
DCHAR(10) to store only digits without formatting
Attempts:
2 left
💡 Hint
Consider storage size and ability to perform numeric comparisons.
🧠 Conceptual
expert
2:00remaining
What happens if you define a column as SERIAL and also specify a default value?
In PostgreSQL, consider this table definition:

CREATE TABLE test (
id SERIAL DEFAULT 1000 PRIMARY KEY
);

What will be the behavior of the id column when inserting rows without specifying id?
AThe sequence starts at 1000 and increments from there
BAn error occurs because SERIAL and DEFAULT cannot be combined
CThe default value 1000 is used for all inserts, ignoring the sequence
DThe sequence generated by SERIAL overrides the default 1000 value
Attempts:
2 left
💡 Hint
Think about how DEFAULT interacts with SERIAL's implicit sequence.