- From: Andy Seaborne <andy.seaborne@talis.com>
- Date: Wed, 11 Nov 2009 10:46:45 +0000
- To: Steve Harris <steve.harris@garlik.com>
- CC: RDF Data Access Working Group <public-rdf-dawg@w3.org>
On 10/11/2009 18:47, Steve Harris wrote: > On 10 Nov 2009, at 18:25, Andy Seaborne wrote: >> On 10/11/2009 17:57, Steve Harris wrote: >>>> > Consensus that SUM/AVG should use same semantics as + >>>> >>>> Clarification: errors not in a group means that what would be >>>> >>>> 1 + error + 2 => 3 >>>> >>>> which is not the same as + >>> >>> Yep, which I think is why they are in the group, and why COALESCE is >>> important. >> >> I don't see that COALESCE helps because there isn't an intermediate >> variable representing the sum so far. > > I think the idea was something like: > > SELECT SUM(COALESCE(xsd:double(?x), 0)) > WHERE { > <x> <value> ?x . > } Thanks - I'd missed that. However, it does not quite follow the semantics of "+" because it changes the datatype: SUM(?x | ?x{1,2,3} ) ==> "6"^^xsd:integer but SUM(COALESCE(xsd:double(?x), 0) | ?x{1,2,3} ) => "6"^^xsd:double Using xsd:integer does not work e.g. 1, 1.5, 3 !=> "5.5"^^xsd:decimal I don't see how to write a MIN that works using COALESCE because there is no natural value that plays the role zero did (e.g. MIN over strings mixed with non-strings). MIN(IF(datatype(?x)=xsd:String, ?x, ???)) And xsd:integers are arbitrary length so the COALESCE idiom is hard for MIN (either definition). If SUM follows +, does MIN follow < or ORDER BY? http://lists.w3.org/Archives/Public/public-rdf-dawg/2009AprJun/0250.html Andy > > That parallels what you do in SQL: > > > SELECT * FROM C; > +------+ > | val | > +------+ > | 1 | > | 2 | > | 5 | > | 23 | > | NULL | > +------+ > > > SELECT SUM(COALESCE(val, 100)) FROM C; > +-------------------------+ > | SUM(COALESCE(val, 100)) | > +-------------------------+ > | 131 | > +-------------------------+ > > - Steve >
Received on Wednesday, 11 November 2009 10:47:06 UTC