I'm running ogr2ogr for a PostGIS to GeoJSON export like this:
ogr2ogr -s_srs EPSG:4326 -f GeoJSON unique_geoms.json "PG:host=localhost dbname=local_data user=local_user password=local_pass" -sql "SELECT MAX(geom)::geometry FROM geom_table GROUP BY ST_AsBinary(geom)"
ogr2ogr isn't very bright, and tries this query on my database:
SELECT ST_SRID("max") FROM(SELECT MAX(geom)::geometry FROM geom_table GROUP BY ST_AsBinary(geom)) AS ogrpggetsrid LIMIT 1
So the database has to run the entire subquery to even get a response! This is fine for small tables, but for really big tables, the operation takes forever.
As you can see, I tried using
-s_srs EPSG:4326 to override the built-in SRID detection, but it doesn't work.
My query is designed to de-duplicate my point geometry. I could create a new table based on this query, but I'm not sure that would help.