Working with databases often involves handling large amounts of data. One of the most common ways to import or export data is through CSV files.
This article covers simple steps for importing and exporting CSV files using pgAdmin.
Let’s get started!
Importing CSV into pgAdmin
-
Right-click on the table where you want to import the CSV file.
- A popup will appear.
- A popup will appear.
-
Click on the folder icon (highlighted in the green square).
- A new popup will open.
- A new popup will open.
-
Click on the three horizontal dots on the right side of the popup.
- A dropdown menu will appear with the “Upload” option.
- A dropdown menu will appear with the “Upload” option.
-
Upload the file.
- After selecting the "Upload" option, a new popup will appear where you can choose your file.
- Note: The maximum file size is 50MB, so make sure your file doesn't exceed this limit.
- After selecting the "Upload" option, a new popup will appear where you can choose your file.
Close the popup by clicking on the first 'X' button. Don’t click the second one as it will remove the file from the list.
-
Ensure the CSV Columns Match the Database.
- Make sure the columns in your CSV match those in your database table.
- In the screenshot below, the database columns are
id
,published_date
,city
, etc.
-
CSV Columns.
- Similarly, ensure that your CSV file has the same columns in the same positions as the database.
-
Note: The
id
column is not included in the CSV because PostgreSQL will generate this automatically.
- Similarly, ensure that your CSV file has the same columns in the same positions as the database.
Excluding Unwanted Columns
-
Exclude unwanted columns.
- In the "Columns" tab, remove the columns that you don’t want to import (e.g.,
id
,created_at
,updated_at
).
- In the "Columns" tab, remove the columns that you don’t want to import (e.g.,
Click OK to complete the import process. Your CSV file will be successfully imported into pgAdmin.
Exporting CSV from pgAdmin
Go to the Export tab and click the folder icon to choose the file location where you want to export your data.
Click the 'Export' button to start the process. Once completed, a success message will appear
Accessing the Exported CSV
-
Where to find your exported CSV file?
- Don’t worry! You can easily find your exported file by clicking on the Tools option in the header, followed by Storage Manager.
- Don’t worry! You can easily find your exported file by clicking on the Tools option in the header, followed by Storage Manager.
Select the file and click on the download button to get your exported CSV file.
Conclusion
And there you have it!
You've learned how to import and export CSV files in pgAdmin easily.
This process is quite simple once you get the hang of it, and it's a great way to manage your data.
Stay Connected - @syedamahamfahim 🐬
Top comments (0)