Guide: run locallygeojson → postgis sql

GeoJSON to PostGIS with ogr2ogr

How to load a GeoJSON file into PostGIS with ogr2ogr, via an SQL file or a direct connection.

The GDAL worker behind this site has no database connection. On your own computer ogr2ogr can write an SQL file for PostGIS (PGDump driver, tested) or write directly into the database (PostgreSQL driver, not tested here).

Guide: run this conversion locally with GDAL

The GDAL worker behind this site has no database connection. Run the commands below with GDAL on your computer.

What the command does

  • The PGDump driver writes an SQL file: DROP TABLE IF EXISTS ... CASCADE, CREATE TABLE, AddGeometryColumn with the SRID (4326 for GeoJSON), one INSERT per feature and a GIST index.
  • Caution: because of DROP TABLE IF EXISTS ... CASCADE, loading the file replaces an existing table of the same name.
  • Lists become PostgreSQL arrays (varchar[]), objects JSON, dates date.

GDAL command to run locally

sh — gdal
$ogr2ogr -f PGDump punkte.sql input.geojson -nln public.punkte

Load the SQL file with psql -f punkte.sql into a database with the PostGIS extension (not tested here). Direct alternative according to the GDAL documentation, also not tested here: ogr2ogr -f PostgreSQL PG:"host=localhost dbname=gis user=postgres" input.geojson -nln punkte

Tested with

Test fileResult
GeoJSON with 4 points and 10 propertiesSQL file with AddGeometryColumn('public','punkte','wkb_geometry',4326,'POINT',2), 4 INSERT statements, tags as ARRAY['bahn','fern'], meta as JSON, GIST index

Tested on 24 Sep 2026 with GDAL 3.10.3 (conda-forge build on Windows). No PostGIS server was available in the test environment; loading the SQL and the direct PG: connection were not tested.

Limits

  • Loading into PostGIS was not tested (no PostGIS server in the test environment).

Frequently Asked Questions

Why an SQL file instead of a direct connection?

The SQL file can be checked before loading and moved to the server. It also works without network access to the database.

Related conversions