0
0
PostgreSQLquery~5 mins

COPY command for bulk data loading in PostgreSQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of the COPY command in PostgreSQL?
The COPY command is used to quickly load large amounts of data into a PostgreSQL table from a file or to export data from a table to a file.
Click to reveal answer
beginner
How do you use the COPY command to load data from a CSV file into a table?
You use: <br> COPY table_name FROM '/path/to/file.csv' WITH (FORMAT csv, HEADER true); <br> This loads CSV data with a header row into the table.
Click to reveal answer
beginner
What is the difference between COPY FROM and COPY TO?
COPY FROM loads data into a table from a file. <br> COPY TO exports data from a table to a file.
Click to reveal answer
intermediate
Can the COPY command read from or write to a client program instead of a file?
Yes, using STDIN and STDOUT, COPY can read data from or write data to the client program, allowing interactive or programmatic data transfer.
Click to reveal answer
intermediate
What permissions are required to use the COPY command with a file path?
The PostgreSQL server process must have read permission on the file for COPY FROM, and write permission for COPY TO. Also, the user must have appropriate table privileges.
Click to reveal answer
Which command loads data from a CSV file into a PostgreSQL table?
ACOPY table_name FROM '/path/file.csv' WITH (FORMAT csv, HEADER true);
BINSERT INTO table_name VALUES ('/path/file.csv');
CLOAD DATA INFILE '/path/file.csv' INTO table_name;
DSELECT * FROM '/path/file.csv';
What does the HEADER option do in the COPY command?
ASkips the first row of the file because it contains column names.
BIncludes the first row as data.
CSpecifies the file has no header.
DEncrypts the data during copy.
Which of these is NOT a valid COPY command usage?
ACOPY table_name TO '/path/file.csv' WITH (FORMAT csv);
BCOPY table_name FROM STDIN;
CCOPY table_name FROM '/path/file.csv' WITH (FORMAT json);
DCOPY table_name FROM '/path/file.csv' WITH (FORMAT csv);
What must the PostgreSQL server have to read a file with COPY FROM?
ARead permission on the file.
BWrite permission on the file.
CExecute permission on the file.
DNo permissions needed.
How can you export data from a table to a CSV file?
ACOPY table_name TO '/path/file.csv' WITH (FORMAT csv, HEADER true);
BCOPY table_name FROM '/path/file.csv';
CINSERT INTO table_name VALUES ('/path/file.csv');
DEXPORT table_name TO CSV;
Explain how to use the COPY command to load data from a CSV file into a PostgreSQL table.
Think about the command structure and options for CSV files.
You got /5 concepts.
    Describe the permissions and security considerations when using the COPY command with files.
    Consider who needs access to the file and the database.
    You got /4 concepts.