Count All Singletons in GSQL

Hi I am looking to return all vertexes with no edges in GSQL (I’d also be interested in a pyTigerGraph solution).

it would be helpful to include some specifics, such as the name of the vertex so that we could produce a working example, but even without those details, we could consider something like this:

start = {VertexToSearch.*};

zerooutdegrees = SELECT s FROM start:s
WHERE s.outdegree() == 0 ;

1 Like

Would it be bad practice to start from {ANY} ?

I guess it depends on the size of your graph and the number of vertex types. I also would be concerned about trying to generate a vertex set with different vertex types. So you would likely need to use my method and do it separately for each vertex type. Another question is whether you actually need to instantiate a vertex set at all, which depends on what you plan to do with it. If you just want to count them, or check for orphans, then you can just use a SumAccum and count them up and not actually return the vertex set.

1 Like

Thanks and would I need a new query for earch vertex type or is there a syntax like, e.g.,

CREATE QUERY my_query(VERTEX d) {
start {d.*}

etc…

Does anyone have an opinion on…

CREATE QUERY check_vertex_count(STRING vertex_type) FOR GRAPH MyGraph {
G = {ANY};

G2 = SELECT s FROM G:s
WHERE s.type == vertex_type;

zerooutdegrees = SELECT s FROM G2:s
WHERE s.outdegree() == 0 ;

PRINT zerooutdegrees;
}

You can do it dynamically by passing Vertex Name as parameter through Python.
just create single dynamic query in GSQL instead of creating multiple queries for each vertex.

1 Like