I have a shape file, I opened it in QGIS that has columns in attribute table named


and I have a database table in Posqgresql that has columns named

  • gid (primary key), city_name, population, geom

Database colums are lowercased names, is this is a problem?

And I want to load shapefile data in existing postgresql database table via shp2pgsql.

shp2pgsql "file.shp" public.cities | -U postgres -a mydb

gives error, Why this error occuring I did not understand. I am giving parameters right.

enter image description here

1 Answer 1


For whatever reasons, the geom column is trying to get into the gid column, hence the error.

If the target is an empty table, you can use the -d option to drop the table and automatically create one as per requirements.

shp2pgsql -d "file.shp" public.cities | -U postgres -a mydb

If the table contains data and if you are not sure how the fresh contents are coming in, it is a good idea to import the shapefile into a new table(using option -c), verify contents and then append the required data to your original table.

shp2pgsql -c "file.shp" public.tempcities | -U postgres -a mydb

Hope this helps!

  • This worked, but there is new problem now. I am copying temp table into main table. But gid is not auto increament. So I could not insert new data beacause of PK duplication.
    – barteloma
    Jun 9, 2014 at 8:49
  • You are probably having a plain numeric field as primary key (gid).
    – veer
    Jun 10, 2014 at 12:19

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.