You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Iain Ritchie <ia...@gmail.com> on 2013/08/01 22:29:57 UTC

Count(*) SPARQL Query Using Jena

Hi,

I would like to execute a COUNT(*) type query in Jena:

SELECT count (*) WHERE {?s ?p ?o}

I get a QueryParseException when trying to execute:

com.hp.hpl.jena.query.QueryParseException Encountered " "count" "count
"" at line 1, column 8.

String queryString = "SELECT count (*) WHERE {?s ?p ?o} ";
Query query = QueryFactory.create(queryString);

Any suggestions how this might be achievable without iterating through
the ResultSet?

Many Thanks in advance.

Re: Count(*) SPARQL Query Using Jena

Posted by Rob Vesse <rv...@yarcdata.com>.
Aggregates and project expressions must be enclosed in brackets and be
aliased I.e.

SELECT (COUNT(*) AS ?count) WHERE { ?s ?p ?o }

Otherwise they are illegal syntax which ARQ rejects.

Hope this helps,

Rob



On 8/1/13 1:29 PM, "Iain Ritchie" <ia...@gmail.com> wrote:

>Hi,
>
>I would like to execute a COUNT(*) type query in Jena:
>
>SELECT count (*) WHERE {?s ?p ?o}
>
>I get a QueryParseException when trying to execute:
>
>com.hp.hpl.jena.query.QueryParseException Encountered " "count" "count
>"" at line 1, column 8.
>
>String queryString = "SELECT count (*) WHERE {?s ?p ?o} ";
>Query query = QueryFactory.create(queryString);
>
>Any suggestions how this might be achievable without iterating through
>the ResultSet?
>
>Many Thanks in advance.