Ali Raza Bhayani
Ali Raza Bhayani

Reputation: 3145

HTSQL - Get Count/number of records to be returned by a query

I am trying to achieve server side pagination with HTSQL and jQuery Datatables with server side being Django. The datatable initially requires total number of records so that it could manage the pagination. So if I have a simple HTSQL query like:

/program

(click the link below for preview)

/program

I would simply do:

/count(program)

/count(program)

and I would get the total number of records which my simple query is going to return. But for instance, if I have a HTSQL query like:

/program.filter(school_code=$code){school_code, code, title}:where($code:='eng')

/program.filter(school_code=$code){school_code, code, title}:where($code:='eng')

(my Queries are much more complex than that but this would do for an example. Like I have distinct '^' as well as nested queries)

and now I want to get a count of number of records I would get if I run this query so that I could further use it to initialize any table for server side pagination. I tried:

/count(program.filter(school_code=$code){school_code, code, title}:where($code:='eng'))

/count(program.filter(school_code=$code){school_code, code, title}:where($code:='eng'))

but got error "Function 'count' expects 1 argument; got 3".

Any clue how could I get the count/number of records which my query is going to return?

Upvotes: 1

Views: 138

Answers (1)

Binary Alchemist
Binary Alchemist

Reputation: 1620

Remove the selector {} from count() and the records count will correct.

/count(program.filter(school_code=$code):where($code:='eng'))

Upvotes: 2

Related Questions