Exercise: The COPY Command
Practice using the COPY command to load data into a PostgreSQL database.
In this exercise, we’ll practice using the COPY
command to load data into a PostgreSQL database. Our task is to create a table named cars
and a function that loads a CSV file into it.
This function will be a part of the load step in an ETL pipeline that uses full loads. Therefore, we need to truncate the table each time we load new data.
Create a table
The CSV file called cars.csv
contains a million records, and has the following format:
Press + to interact
ProductID,Company,CarName,Price,Quantity1,Toyota,Camry,89915.37,72,Tesla,Model S,34397.88,63,Volvo,XC60,88356.36,94,Ferrari,SF90488,19463.69,75,Mazda,CX-5,69653.82,46,Toyota,Camry,41087.01,17,Tesla,Model S,71948.6,108,Jeep,Wrangler,73004.64,29,Toyota,Camry,52439.4,7
Our first step is to create a table to store this data. Create a table with ...