I have a bunch of thousands of points. I'd like to group them, in a user-defined number of clusters for example or based on some kind of "best number of clusters", based for example on their relatives distances. Which kind of algorithm is available on postGIS and/or shapely (preferred) to do that? I can simply make some buffers around them and a union but I wonder if there is some other advanced technique that are computationally efficient on large dataset.
I've found the DBSCAN algorithm  interesting and it seems rather simple to insert in an existing code. There is also the OPTICS algorithm  but it seems harder to find a solution.
Anyway, I'm stuck with DBSCAN now:
how to store the cluster label in which a point lays within a new column "cluster" in a postgreSQL table? Actually, the points ID are not stored along their coordinates within the cluster...
Some checking operations on coordinates in order to retrieve points IDs in original array would be a bit overrated, in my opinion.