How to apply pagination and offset on GSQL Queries

Hi team
I am struggling in finding out , how to apply pagination and offset in our GSQL queries

I found out the below link but this is only for Graph Query Language
https://docs.tigergraph.com/graphql/current/pagination

I have a full stack application Angular application Python Backend where I have lots of Custom GSQL queries in my TG instance, which I am calling from tiger.call_installed_query(“get_all_profiles”)
tiger.call_installed_query(“get_all_segments”)
tiger.call_installed_query(“get_insights”)

and one more question how to apply slicing in GSQL queries like

CREATE QUERY all_Profiles(INT start, INT end) FOR GRAPH clientA_sga {
res = select s from profile:s [start:end];
PRINT res;
}

all_Profiles(0, 100) starting 100 profiles in result
all_Profiles(100, 200) after 100 to 200 profiles in result

how to apply this type of slicing ?

Thanks,

Hi pkr2,

Pagination is supported in the LIMIT OFFSET clause. You can implement it like below:

CREATE QUERY pagination(INT numPerPage, INT pageNum = 0) FOR GRAPH friendNet SYNTAX V1
{
        start = {person.*};
        result2 = SELECT v FROM start:v
                ORDER BY v.id
                LIMIT numPerPage OFFSET pageNum * numPerPage;

        PRINT result2[result2.id]; // api v2
}

The only stipulation here is that you NEED the ORDER BY clause in order for pagination via LIMIT to function.

3 Likes