I'm attempting to import a GeoJSON file into PostGIS using ogr2ogr

The basic command is

ogr2ogr -f "PostgreSQL" PG:"dbname=my_db user=postgres" my_file.geojson -preserve_fid -nln geo_table -append

Using this sample how do I rewrite it so the id becomes a id Colum in the database table?



ERROR 1: ERROR: setval: value 0 is out of bounds for sequence

The "real" file contains both Polygon & MultiPolygon

1 Answer 1


From the GeoJSON specification https://www.rfc-editor.org/rfc/rfc7946:

If a Feature has a commonly used identifier, that identifier SHOULD be included as a member of the Feature object with the name "id", and the value of this member is either a JSON string or number.

Your GeoJSON has id at wrong level as a member of Polygon object. Move it higher.

{ "type": "Feature", "id": 123, "properties": {"geometry":{"type":"Polygon","coordinates":[[[100,0],[101,0],[101,1],[100,1],[100,0]]]}}}

Your Answer

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

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