How to import CSV file data into a PostgreSQL table?
steps:
Need to connect postgresql database in terminal
psql -U postgres -h localhost
Need to create database
create database mydb;
Need to create user
create user siva with password 'mypass';
Connect with database
\c mydb;
Need to create schema
create schema trip;
Need to create table
create table trip.test(VendorID int,passenger_count int,trip_distance decimal,RatecodeID int,store_and_fwd_flag varchar,PULocationID int,DOLocationID int,payment_type decimal,fare_amount decimal,extra decimal,mta_tax decimal,tip_amount decimal,tolls_amount int,improvement_surcharge decimal,total_amount
);
Import csv file data to postgresql
COPY trip.test(VendorID int,passenger_count int,trip_distance decimal,RatecodeID int,store_and_fwd_flag varchar,PULocationID int,DOLocationID int,payment_type decimal,fare_amount decimal,extra decimal,mta_tax decimal,tip_amount decimal,tolls_amount int,improvement_surcharge decimal,total_amount) FROM '/home/Documents/trip.csv' DELIMITER ',' CSV HEADER;
Find the given table data
select * from trip.test;