1

I am trying to load postgis.sql files into a pgAdmin database (using psql) that has already been created so I can create a spatially enabled database. I have confirmed that the language "plpgsql" already exists, but I cannot execute the following functions:

psql -d yourdatabase -f lwpostgis.sql;
psql -d yourdatabase -f lwpostgis_upgrade.sql;
psql -d yourdatabase -f spatial_ref_sys.sql;

I just get the generic "syntax error at or near...".

Maybe I am not formatting the line right, because from what I have read, this should work? do I really need "psql"? what does "-d" do? I tried without psql in front of the commands and bupkiss. Thoughts are appreciated...thanks.

Beardo
  • 65
  • 1
  • 2
  • 9
  • pgAdmin is the GUI. You mean PostgreSQL? Add version numbers to involved software, please. – Erwin Brandstetter Nov 07 '12 at 18:20
  • my bad; yes, I do mean PostgreSQL, version 8.3.7, psql version 9.1.4. – Beardo Nov 07 '12 at 18:37
  • The commands you quote are meant to be input in a shell interpreter or cmd.exe if using MS-Windows. From bits of your question, it looks like you're already into some other program (presumably pgAdmin or psql itself) when you're typing this. – Daniel Vérité Nov 07 '12 at 21:26
  • @Daniel - thank you for the info! I am indeed typing these commands in psql from my computer. The database, postGIS and PostgreSQL are on a server and computer down the hall. pgAdmin is on my machine here...will this not be possible through psql? – Beardo Nov 07 '12 at 21:47
  • Sure it's possible, I've submitted an answer to that effect but you need to leave pgAdmin out of the way. psql and pgAdmin are mutually exclusive. – Daniel Vérité Nov 07 '12 at 22:54
  • 1
    gotcha - I was accessing psql through the pulgins menu in pgAdmin III – Beardo Nov 07 '12 at 23:13

1 Answers1

0

The -d yourdatabase option connects to this database once psql has started.
The -f file.sql option says to load file.sql and execute all the SQL commands it contains.

If you're already inside psql, the equivalent commands would be:

\c yourdatabase: connect to the db named yourdatabase.

\i file.sql: loads file.sql and execute all commands in it. It should be in the current path, otherwise specify a full path.

Daniel Vérité
  • 58,074
  • 15
  • 129
  • 156
  • @ Daniel - thank you for the help. I actually found out that the problem was I could not path to the server correctly. I ended up having the individual files put on my computer and uploaded them using phpPgAdmin because psql didn't execute the files and gave me errors...lots of them. – Beardo Nov 07 '12 at 23:16