I was looking to use ST_ClusterDBSCAN on a set of points that also have a type. So I want the points to be clustered by type, so that points having different types won't end up in the same cluster. Since ST_ClusterDBSCAN is windowed function I thought I could simply PARTITION BY type column and that will do. Something like:

ST_ClusterDBSCAN(point, eps := 20, minpoints := 3) OVER(PARTITION BY type) AS cid,

However I still end up having same cid assigned to points of different type.

enter image description here

Obviously there's something I misunderstand either about clustering or windowed functions in general?

ST_ClusterDBSCAN assigns cids differently with and without of PARTITION BY type so partitioning definitely affects the outcome somehow, I'm just not sure how exactly. Obviously not the way one would expect.

  • maybe records 2 and 3 are more than 20 units away from eachother so they would never be in a cluster regardless?
    – ziggy
    Commented Apr 10, 2020 at 18:57

1 Answer 1


The cluster IDs are unique to each partition. You can read about how window functions work here.

  • 1
    Are you sure about cluster IDs are unique to each partition part? Or it's just guess? I mean I came to the same conclusion, but would great to have a confirmation from some official doc.
    – jayarjo
    Commented Apr 11, 2020 at 12:19
  • Yes, I'm sure. You can read the documentation I linked to in the answer.
    – dbaston
    Commented Apr 11, 2020 at 14:21

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.