Q: How to import a CSV file into a PostgresSQL database? I have already created a table with 12 columns, and my CSV data have some column values.
For example, in the database I created a table named book with columns b_name, author, age, address, year, publishers, no of sale, categories, etc.
But my CSV file has the columns b_name, year, publishers, no of sales, author
Now I want to import the data into my database.

A: You can use the cursor.copy_from function.
In columns, specify the table columns that correspond to the CSV file columns in the correct order. If there are any table columns that do not occur in the file, omit them, and those columns will be filled with NULL values.

A: Try using COPY statement.
COPY book(b_name, year, publishers, no of sales, author)
FROM 'CSV Location'
DELIMITER ','
CSV HEADER;

Use HEADER keyword if your CSV file contains Header.
As it is a CSV file we need to use DELIMITER Keyword as well as CSV.
