MapQuest / MapQuest-Mapnik-Style

MapQuest Branded style for use with Mapnik and OSM
open.mapquest.co.uk
93 stars 25 forks source link

SQL error in placenames-country #11

Closed pnorman closed 12 years ago

pnorman commented 12 years ago

When rendering I get the error

RuntimeError: :
ERROR:  operator does not exist: text > integer
LINE 8:         case when population > 0 then population else -1 end...
                                     ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
Full sql was: 'SELECT * FROM
            (select way,
      case when "name:en" is null then name
           when name is null then "name:en"
           when length(btrim(replace(name, "name:en", ''), '()- ')) = 0 then "name:en"
           else "name:en" || E'\n(' || btrim(replace(name, "name:en", ''), '()- ') || ')'
      end as name,
        case when population > 0 then population else -1 end as population
       from planet_osm_point
       where place in ('country')
order by population desc) as countries
           LIMIT 0'
 (encountered during parsing of layer 'placenames-country' in map '/home/pnorman/osm/mapnik/MapQuest-Mapnik-Style/mapquest-us.xml')

This is with postgresql 9.1.3

Changing the SQL to

case when CAST(population as integer) > 0 then CAST(population as integer) else -1 end as population

fixed this, but I am not sure if this is reliable in the case of malformed data (e.g. someone puts free-form text in the population field)

Similar issues may be present elsewhere. If the above changes don't cause errors with invalid data I can submit a patch if desirable.

zerebubuth commented 12 years ago

Thanks for pointing this out as well. We use a slightly different osm2pgsql style file, included in commit 3e490eae4b8, which changes the column type for population to int4, which should eliminate the error you mention.