W3C home > Mailing lists > Public > public-rdf-dawg@w3.org > October to December 2009

Re: "Unbound" in SPARQL (was Re: [TF-LIB] COALESCE is an unhelpful choice of name)

From: Andy Seaborne <andy.seaborne@talis.com>
Date: Mon, 16 Nov 2009 20:14:04 +0000
Message-ID: <4B01B28C.4000800@talis.com>
To: Steve Harris <steve.harris@garlik.com>
CC: "public-rdf-dawg@w3.org Group" <public-rdf-dawg@w3.org>


On 15/11/2009 18:12, Steve Harris wrote:

> It's a little unfortunate because we might have to return an error from
> a MIN (etc.) over an empty multiset, which isn't ideal for some usecases:
>
> data:
>
> :alice a :Salesperson ;
> :sales [
> :date "2009-11-14" ;
> :volume 12 ;
> ] , [
> :date "2009-11-14" ;
> :volume 9 ;
> ] .
> :bob a :Salesperson ;
> :sales [
> :date "2009-11-14" ;
> :volume 8 ;
> ] .
> :carol a :Salesperson .
>
> query:
>
> SELECT ?x (MAX(?sales) AS ?bestDay)
> WHERE {
> ?x a :Salesperson .
> OPTIONAL {
> ?x :sales [
> :volume ?sales ;
> ]
> }
> }
> GROUP BY ?x
>
> results:
>
> ?x = :alice, ?bestDay = 12
> ?x = :bob, ?bestDay = 8
> [no row for :carol because we can't return "unbound"/null from MAX(?sales)]
>

Would this work?

SELECT ?x ( TRY(MAX(?sales), -1) AS ?bestDay)

or other choice of marker for no value.

	Andy
Received on Monday, 16 November 2009 20:14:19 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 16:15:40 GMT