Search code examples
pgadmin-4

How to generate Insert statement from PGAdmin4 Tool?


We are writing a new application, and while testing, we will need a bunch of dummy data. I've added that data by using MS Access to dump excel files into the relevant tables into the Postgres database.

What should I do now to generate an Insert statements from the PGAdmin4 Tool similar to what SQL Studio allow us to generate an Insert statements for SQL Server? There are no options available to me. I can't use the closest one, which is to export and import the data via CSV.


Solution

  • I understand that you cannot import the CSV file into the actual DB as this needs to be done through ASP.NET core EF. Perhaps, you can probably create a test schema and import the CSV file into the test schema. Once you have the data imported into the test schema, you can use that to generate SQL statements using the steps below:

    • Right click on target table and select "Backup".
    • Select a file path to store the backup. You can save the file name as data.backup
    • Choose "Plain" as Format.
    • Open the tab "Options" check "Use Column Inserts".
    • Click the Backup-button.
    • Once the file gets generated you can open with Notepad++ or VSCode to get the SQL insert statements
    • You can use the statements generated and delete the test schema created

    Here is a resource that might help you in loading data from Excel file into PostgresSQL if you still need to take this path Transfer Data from Excel to PostgreSQL