6

I'm new to PostGIS. I'm trying to perform a dissolve operation on polygons depending on a particular attribute fields called priFunc and priForm. My SQL query is

   SELECT ST_Union(geom) AS new_geom, priFunc, priForm
   FROM os_greenspace_layer
   GROUP BY priFunc, priForm

This works fine and my output looks like this

enter image description here

Next, I'd like to remove any features which have a priForm of "Manmade Surface" and omit them completely. So the code now is

   SELECT ST_Union(geom) AS new_geom, priFunc, priForm
   FROM os_greenspace_layer
   WHERE priForm <> 'Manmade Surface'   
   GROUP BY priFunc, priForm

This gives an output that looks like this

enter image description here

So that works, but it also removes all the features where priForm is NULL and I want to keep those. I've tried using COALESCE to assign a value to the NULL fields but that doesn't seem to work.

How can I do this?

0
4

How about:

SELECT ST_Union(geom) AS new_geom, priFunc, priForm
FROM os_greenspace_merged_clipped 
WHERE priForm <> 'Manmade Surface' or priForm is null
GROUP BY priFunc, priForm
1
  • 2
    That's great. Thank you. Yes, that works. SQL really requires a different mindset which I'm still struggling to get my head around so apologies for asking obvious questions. – Ddee May 10 at 12:34
6

You can use IS DISTINCT FROM or IS NOT DISTINCT FROM to compare for (in)equality considering the null being not equal to a value

 SELECT ST_Union(geom) AS new_geom, priFunc, priForm
   FROM os_greenspace_layer
   WHERE priForm IS DISTINCT FROM 'Manmade Surface'   
   GROUP BY priFunc, priForm
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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