You can easily import data if you have access to PostgreSQL DB using pgAdmin but if you need to automate the process of importing the CSV file data then you should use psql command line to import the data. This aricle will show how it can be achieved.
Pre-requisite: Install psql, in this example, use below commands for ubuntu OS.
You can use \copy using DB client to import CSV data file. You don’t need to write big scripts. Just take care of 2 points when data is exported from the origin table to be imported later.
- When table data is exported make sure the settings are as shown in screen shot. Delimiter, quote and escape is very important when this data is imported in another table in some other DB.
2. Also export the script to create the table. Right click on Table–>scripts–>CREATE Script, this will provide the script to create table and indexes and other db objects required fro the table.
Once data is exported properly then we can follow the steps to import it. In this example the data is imported into AWS RDS PostgreSQL from laptop (WSL Ubuntu)-
Note:the order of column exported should be the order of column imported. Else the data will get into wrong columns.
For more details follow the link