Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Does ogrinfo support a GROUP BY clauses? I could not find any good documentation of all the SQL syntax features it supports.

I tried the following:

ogrinfo . -geom=no -sql 'SELECT lsad FROM tl_2011_us_county GROUP BY lsad'

And got the following error:

ERROR 1: SQL: Failed to parse SELECT statement, extra input at BY token.
INFO: Open of `.'
      using driver `ESRI Shapefile' successful.

What I really want to do:

SELECT lsad, count(*)
FROM tl_2011_us_county

What I can do:

FROM tl_2011_us_county

And then:

SELECT count(*)
FROM tl_2011_us_county
WHERE lsad = 'foo'

... but that is annoying.

share|improve this question
up vote 5 down vote accepted

Depends on the datasource - if OGR needs to fall back to OGR SQL (like when using shapefiles) then no. But if you are using PostGIS for instance you can use GROUP BY.

share|improve this answer
I am in a catch 22 then. I wanted to inspect the shapefiles before I insert them in my postgis table, but to do it conveniently, I must insert them into a postgis table. Oh well. thanks! – kzh Jun 24 '12 at 16:13

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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