0

I want to upload a .sql or .xml file in postgresql database using terminal. I saw several solution as I linked followed, but unfortunately none of them works.

It would be nice to get an example. I'm using psql (PostgreSQL) 9.1.5. in Linux environment. Thanks in advance. Possible duplicate: Link-1, Link-2,Link-3, Link-4

Community
  • 1
  • 1

1 Answers1

-1

If the .sql file is simply text with with SQL queries in it, then the proper way is:

psql -U some_username -d some_database -f name_of_the_file

What the .xml file is - I don't know. As far as I know, no native PostgreSQL tools produce XML dumps of database.

If the above wouldn't work, show us part of the file, how you ran it, and what did you get.

  • My database structure is as this link: http://codepad.org/AtYLV5on I tried with the command you suggested but it does not even work. FYI, first I connected with the specific database ( command \c database_name) where I want to import all the tables and then I run your command. I dont even get any error message. Another info, I can run other command like create table or insert in the table using the postgreysql command. –  Jun 30 '13 at 13:02
  • Sorry, but I dont understand your comment. \c is command within psql. And I showed how to run psql with file from shell. –  Jun 30 '13 at 13:08
  • Regarding the name_of_the_file parameter: don't I have to locate the file where it is in my machine. Yes, I run postgreysql command where this file is located. Thanks. –  Jun 30 '13 at 13:09
  • 1. It's PostgreSQL, not "postgreysql". 2. I have absolutely no idea what you mean by "locate the file". –  Jun 30 '13 at 13:10
  • So if I run it from the shell how do I specify the host address ? –  Jun 30 '13 at 13:10
  • What host address? Host of what? Please specify your questions in understandable way. Also - I checked the "structure" link you gave me. It's clearly MySQL creation script, and as such will not work (without some modifications) in PostgreSQL. –  Jun 30 '13 at 13:11
  • Sry for confusion, what I mean is the path of .sql file for instance /Users/Cris/Desktop/the_file.sql –  Jun 30 '13 at 13:12
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/32639/discussion-between-depesz-and-user2412714) –  Jun 30 '13 at 13:12
  • In my server I have PostgreSQL DB and my dump database is located in this location of my machine /Users/Cris/Desktop/the_file.sql I just want to import this the_file.sql in my server –  Jun 30 '13 at 13:15