I'm using OSM-Data via PostGIS (osm2pgsql). To draw a highway with and without bridges or tunnels, I use the following expressions:

The highway:

"highway" = 'motorway' AND "bridge" IS NOT 'yes' AND "tunnel" IS NOT 'yes'

To draw bridges and tunnels for their own I use that expressions:

"highway" = 'motorway' AND ("bridge"  =  'yes' OR "bridge"  =  'suspension')

"highway" = 'motorway' AND "tunnel"  =  'yes' 

So far so good. Was working fine for me for years, but now I kept an eye on my PostGIS log and found that:

Result: 7 (ERROR:  syntax error at or near "'yes'"
        LINE 1: ...h') OR ("highway" = 'footway')) AND ("bridge" IS NOT 'yes'))

It seems, there is something working wrong, but what? Bridges, tunnels and the highways are drawn as they should - I can not see any error, but PostGIS is telling me something else. Is there a better way to draw OSM-Roads with bridges and tunnels?

ADD: the whole line:

2016-11-08T22:12:43 1   1 cursor states lost.
        SQL: DECLARE qgis_9 BINARY CURSOR FOR SELECT st_asbinary("way",'NDR'),"gid","route"::text,"service"::text,"name"::text,"aeroway"::text,"tunnel"::text,"highway"::text,"bridge"::text,"railway"::text,"ref"::text FROM "public"."planet_osm_line" WHERE ("way" && st_makeenvelope(426908.41326787287835032,5749630.84951520431786776,436049.76744384958874434,5752852.1516018183901906,32632)) AND (((((((("highway" = 'path') OR ("highway" = 'footway')) AND ("bridge" IS NOT 'yes')) AND ("tunnel" IS NOT 'yes')) AND ("bridge" IS NOT 'suspension')) OR ((("highway" = 'path') OR ("highway" = 'footway')) AND ("tunnel" = 'yes'))) OR ((("highway" = 'path') OR ("highway" = 'footway')) AND (("bridge" = 'yes') OR ("bridge" = 'suspension')))))
        Result: 7 (ERROR:  syntax error at or near "'yes'"
        LINE 1: ... OR ("highway" = 'footway')) AND ("bridge" IS NOT 'yes')) AN...
  • For not equal comparison, shouldn't you use !=? instead of IS NOT Commented Nov 8, 2016 at 20:54
  • 2
    Please add also the whole line that leads to error.
    – user30184
    Commented Nov 8, 2016 at 21:09
  • 2
    Quite a long query. I would start debugging by rewriting the WHERE to have first just AND "highway"='path' and adding more elements one by one and testing the query with pgAdmin after each addition.
    – user30184
    Commented Nov 8, 2016 at 21:33

1 Answer 1


I believe you are using the IS NOT syntax instead of the IS DISTINCT FROM syntax.

If what you want is all records where bridge is equal to 'no' or is NULL and tunnel is equal to 'no' or is NULL, then the correct syntax would be :

"bridge" IS DISTINCT FROM 'yes' AND "tunnel" IS DISTINCT FROM 'yes'

IS NOT is meant to be used with booleans, i.e. expression IS TRUE or expression IS NOT TRUE.

See https://www.postgresql.org/docs/current/static/functions-comparison.html

As for why this would work, I have no idea.

Your Answer

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

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