0
0
PostgreSQLquery~20 mins

COPY command for bulk data loading in PostgreSQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
COPY Command Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of COPY command with CSV file
Given a CSV file named 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;
A3 rows copied.
BError: missing permissions to read file.
C0 rows copied.
DSyntax error near 'CSV HEADER'.
Attempts:
2 left
💡 Hint
The CSV HEADER option tells PostgreSQL to skip the first line as column names.
📝 Syntax
intermediate
2:00remaining
Identify syntax error in COPY command
Which COPY command syntax is correct to load data from a CSV file into a table employees?
ACOPY employees FROM '/path/to/file.csv' HEADER CSV DELIMITER ',';
BCOPY employees FROM '/path/to/file.csv' CSV DELIMITER ',' HEADER;
CCOPY employees FROM '/path/to/file.csv' DELIMITER ',' HEADER CSV;
DCOPY employees FROM '/path/to/file.csv' DELIMITER ',' CSV HEADER;
Attempts:
2 left
💡 Hint
The order of options matters in COPY command syntax.
optimization
advanced
2: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?
AUse COPY with FORMAT 'binary' instead of CSV.
BRun COPY inside a transaction with autocommit enabled.
CDisable indexes and constraints before COPY, then re-enable them after.
DLoad data row by row using INSERT statements inside COPY.
Attempts:
2 left
💡 Hint
Indexes and constraints slow down inserts during bulk loading.
🔧 Debug
advanced
2:00remaining
Troubleshoot COPY command error
You run this command:
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?
AThe PostgreSQL server process does not have read permission on the file.
BThe file path is incorrect or file does not exist.
CThe CSV file is malformed and cannot be read.
DThe COPY command syntax is invalid.
Attempts:
2 left
💡 Hint
Check file permissions and ownership for the PostgreSQL server user.
🧠 Conceptual
expert
2:00remaining
Understanding COPY FROM STDIN usage
Which statement about the COPY ... FROM STDIN command in PostgreSQL is true?
AIt automatically creates the target table if it does not exist.
BIt allows streaming data from the client application into the database.
CIt reads data only from a server-side file specified by a path.
DIt can only be used with binary format, not CSV.
Attempts:
2 left
💡 Hint
STDIN means standard input from the client, not a file on the server.