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 (
    image_type VARCHAR(1000),
    image_path VARCHAR(1000),
    boundary GEOGRAPHY(POLYGON, 4326),
    image_time TIMESTAMP,

Error message:

ERROR:  type "geography" does not exist
LINE 5:     boundary GEOGRAPHY(POLYGON, 4326),
  • 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, 2011 at 19:54
  • sounds like 'Geography' has not been created in the first place. postgis.refractions.net/docs/…
    – Mapperz
    Aug 12, 2011 at 20:54
  • @Mapperz - I'm not sure what you mean. It looks like your link shows that Geography does exist.
    – Steph
    Aug 12, 2011 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, 2011 at 8:16

2 Answers 2


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

  • 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, 2011 at 18:34

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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