Alex Street
Alex Street

Reputation: 3

Loading sample database into Postgres

first time user.

I purchased a book called SQL for Data Analytics and it comes with a dump file ("data.dump") (link below).

https://github.com/TrainingByPackt/SQL-for-Data-Analytics/tree/master/Datasets

The book advised installing PostgreSQL which I have done and then loading the dump file via command line (see image below).

For some reason, I am able to create the database via command line (it appears in pgAdmin) but nothing happens when I load the dump file.

postgres=# CREATE DATABASE sqlda TEMPLATE template0;

postgres=# psql < /Users/ast12/Documents/data.dump

I have also tried loading the dump file directly via pgAdmin. Again, nothing happens. I'm at a total loss. I bought the book to learn but with my limited knowledge, I can't even set up the environment to do so. enter image description here]1

Upvotes: 0

Views: 1283

Answers (1)

user330315
user330315

Reputation:

If you are already inside the psql prompt, there is no need to call or run psql again.

After you created the database, you need to switch to it, then run the SQL script using the command \i

postgres=# CREATE DATABASE sqlda;
postgres=# \connect sqlda 
postgres=# \i /Users/ast12/Documents/data.dump

\connect sqlda changes to the newly created database, and \i loads and runs the SQL script.

For an explanation on why nothing happened for your second command, see In psql, why do some commands have no effect?

Upvotes: 1

Related Questions