0

I have 2 files and want to import them to PostgreSql using pgAdmin4 so the only way I know is to create the tables and manually create the columns and every thing from the beginning, but this will take a lot of time hoping I didn't miss any thing, so any way to simply import them and PostgreSql consider the headers as the columns, creates the tables and saves me tons of time. I'm new to all of this so my question form maybe wrong but this is the best I can ask.

Yared
  • 2,044
  • 1
  • 22
  • 29
  • 2
    Pgadmin 4 does not have any import capabilities more sophisticated than you have already described. You can check here to see if you can find a different GUI that has fancier import tools. Or you can write your own script that reads the CSV file, extracts the headers, creates a table, and does the import. My guess is that for only two files, the fastest way is the one you already described. – bfris Aug 20 '21 at 20:28
  • You can look at [Pandas](https://pandas.pydata.org/docs/) in particular [read_csv](https://pandas.pydata.org/docs/user_guide/io.html#io-read-csv-table) and [to_sql](https://pandas.pydata.org/docs/user_guide/io.html#io-sql). Though as @bfris said this may be more overhead then you need for just two files. – Adrian Klaver Aug 20 '21 at 20:50
  • 2
    Does this answer your question? [Can I automatically create a table in PostgreSQL from a csv file with headers?](https://stackoverflow.com/questions/21018256/can-i-automatically-create-a-table-in-postgresql-from-a-csv-file-with-headers) – bfris Aug 20 '21 at 20:55
  • `consider the headers as the columns , creates the tables and saves me tons of time .` < – wildplasser Aug 21 '21 at 12:31
  • 1
    @wildplasser. For the purpose of importing data to a staging table it is not nonsensical. In fact it is pretty common practice. – Adrian Klaver Aug 21 '21 at 14:13
  • I know. I do it all the time. I even have script-generating programs for it. But, even if done by hand, it is only a fraction of the work. – wildplasser Aug 21 '21 at 14:49
  • Check for online tool that will help you to generate query: https://www.convertcsv.com/csv-to-sql.htm , https://sqlizer.io/ – Hiren Patel Aug 25 '21 at 04:51

0 Answers0