[Mulgara-general] Using <mulgara:is> when $x $y $z doesn't exist

Alex Hall alexhall at revelytix.com
Tue Dec 16 20:29:38 UTC 2008


Rui Castro wrote:
> Hi Alex,
> 
> Thank you very much for your answer.
> I found a solution using ITQL that is to do a subquery. Like this:
> 
> select
> 	$pid $level
> 	subquery(
> 		select $parentPID
> 		from <#ri>
> 		where $parentPID <http://roda.dgarq.gov.pt/#parent-of> $pid
> 	)
> from <#ri>
> where
> 	$pid <http://roda.dgarq.gov.pt/#description-level> $level
> 
> This gives me results like this:
> 
> "pid","level","parentPID"
> roda:1,fonds,null
> roda:2,series,roda:1
> roda:3,series,roda:1

Yes, there are several different ways to accomplish what you're looking for.
>From a performance standpoint, I would avoid doing a subquery, as that gets
evaluated once for each row in the outer query.  For large result sets, or for
queries that get repeated many times, that's a bad thing.  If you're constrained
to using TQL (as opposed to SPARQL) you could also try something like:

select $pid $level $parent from <#ri>
where ($pid <roda:description-level> $level and $parent <roda:parent-of> $pid)
   or ($pid <roda:description-level> $level minus $x <roda:parent-of> $pid);

The first part selects all $pid values that do have parents, and the second
selects all $pid values that do not have parents.

Regards,
Alex



More information about the Mulgara-general mailing list