Challenge - 5 Problems
COPY Command Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of COPY command with CSV file
Given a CSV file named
and a PostgreSQL table
data.csv with the following content:id,name,age 1,Alice,30 2,Bob,25 3,Charlie,35
and a PostgreSQL table
persons(id INT, name TEXT, age INT), what will be the result of running this command?COPY persons FROM '/tmp/data.csv' CSV HEADER;
PostgreSQL
COPY persons FROM '/tmp/data.csv' CSV HEADER;
Attempts:
2 left
💡 Hint
The CSV HEADER option tells PostgreSQL to skip the first line as column names.
✗ Incorrect
The COPY command reads the CSV file and inserts 3 rows into the table. The HEADER option skips the first line which contains column names.
📝 Syntax
intermediate2:00remaining
Identify syntax error in COPY command
Which COPY command syntax is correct to load data from a CSV file into a table
employees?Attempts:
2 left
💡 Hint
The order of options matters in COPY command syntax.
✗ Incorrect
The correct syntax places CSV and HEADER options after DELIMITER, in the order: DELIMITER ',' CSV HEADER.
❓ optimization
advanced2:00remaining
Best practice for fast bulk loading with COPY
You want to load a large CSV file into a PostgreSQL table as fast as possible. Which practice will improve COPY command performance?
Attempts:
2 left
💡 Hint
Indexes and constraints slow down inserts during bulk loading.
✗ Incorrect
Disabling indexes and constraints before bulk loading reduces overhead, speeding up COPY. Rebuilding indexes after is more efficient.
🔧 Debug
advanced2:00remaining
Troubleshoot COPY command error
You run this command:
and get the error:
What is the most likely cause?
COPY sales FROM '/data/sales.csv' CSV;
and get the error:
ERROR: could not open file "/data/sales.csv": Permission denied
What is the most likely cause?
Attempts:
2 left
💡 Hint
Check file permissions and ownership for the PostgreSQL server user.
✗ Incorrect
The error indicates a permission problem accessing the file, not a syntax or file content issue.
🧠 Conceptual
expert2:00remaining
Understanding COPY FROM STDIN usage
Which statement about the
COPY ... FROM STDIN command in PostgreSQL is true?Attempts:
2 left
💡 Hint
STDIN means standard input from the client, not a file on the server.
✗ Incorrect
COPY FROM STDIN streams data from the client to the server, useful for programmatic bulk loading.