How can I paginate a SOW query?

AMPS includes the skip_n option, which provides the ability to skip a set number of rows from a SOW query. Combined with the top_n and OrderBy options, this makes it easy to paginate a SOW query.

For example, if you have a set of messages like this:

orderId=204;date=2015-08-02;customer=John;...
orderId=194;date=2014-07-11;customer=David;...
orderId=72;date=2015-02-13;customer=Jill;...
orderId=102;date=2015-03-09;customer=Sue;...

You could split these into pages of 2 records (using 2 just to keep things short / simple) by submitting a query with OrderBy set to /orderId, the top_n=2 option, and a skip_n=x option. In this case, x is set to 2 * (the page number to retrieve - 1).

For example, to render the first page, the SOW query would have these modifiers:

OrderBy: /orderId
options: top_n=2,skip_n=0

To render the second page, the SOW query would include:

OrderBy: /orderId
options: top_n=2,skip_n=2

... and so on, throughout the results.

AMPS also provides support for paginated sow and subscribe. This provides paginated results during the query, and only provides messages to the subscription that would fall within the specified page of results. See the AMPS User Guide section on Paginated SOW and Subscribe for more details.

Last updated