Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have a sql script that creates several tables, a trigger, and a trigger function. All the commands work in pgAdmin when I execute them in the "Query" section. My goal is to put all these commands in a script so that I can set up the database on any machine relatively easily and quickly. When I attempt to run the script through psql, however, I get the following errors on all of the lines where I attempt to use Geography types:

ERROR:  type "geography" does not exist

It doesn't make sense because I can copy and paste the exact same queries into the query editor of pgAdmin and it works just fine. Does psql not support PostGIS? Or maybe just not the most recent version of PostGIS, 1.5.3, which includes the new Geography types? Is there something I can do to fix this?

An example of one of my queries:

CREATE TABLE source_imagery (
    id SERIAL PRIMARY KEY,
    image_type VARCHAR(1000),
    image_path VARCHAR(1000),
    boundary GEOGRAPHY(POLYGON, 4326),
    image_time TIMESTAMP,
    catalog_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Error message:

ERROR:  type "geography" does not exist
LINE 5:     boundary GEOGRAPHY(POLYGON, 4326),
                     ^
share|improve this question
3  
Just to be clear, you're running the same script on the same server and database through pgAdmin and psql? There's no reason it would work in one front-end and not the other. –  Sean Aug 12 '11 at 19:54
    
sounds like 'Geography' has not been created in the first place. postgis.refractions.net/docs/… –  Mapperz Aug 12 '11 at 20:54
    
@Mapperz - I'm not sure what you mean. It looks like your link shows that Geography does exist. –  Steph Aug 12 '11 at 21:51
    
Are you absolutely sure that you connect to the right database? Remember, the syntax for connecting is psql -U username database –  Ragnar123 Aug 15 '11 at 8:16
add comment

2 Answers 2

up vote 5 down vote accepted

If PGAdmin is definitely succeeding at operations involving the geography type, then I can only suggest making sure that psql and PgAdmin are actually connected to the same database. The error reported by psql is from the server, psql is just the messenger. are you specifying a spatially-enabled database when you invoke psql? If not, see http://postgis.net/docs/postgis_installation.html#templatepostgis

share|improve this answer
1  
Ah, you were correct. My problem was that my script was creating the database and then trying to create the tables from the same database. I had to separate the script into two parts. The first script connects to psql via the postgres database and then builds the PostGIS database. The second script connects to psql via the newly created database and then creates all the tables, etc. Sorry for my confusion, and I appreciate your help. –  Steph Aug 15 '11 at 18:34
add comment

The error message comes from the database server, not from the client (psql in your case). The database you are connected to, doesn't have the geography type. Install PostGIS in this database first, or connect to a database that has PostGIS already installed.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.