[Mulgara-dev] Problem w/ "insert select ..."

Eric Brown yogieric.dev at gmail.com
Thu Mar 29 19:30:13 UTC 2007


Hi Andrae,

On Mar 29, 2007, at 1:33 AM, Andrae Muys wrote:

>
> On 29/03/2007, at 5:45 PM, Eric Brown wrote:
>> Hm. Well, using the shorter form of what I need isn't as  
>> verbose... so maybe I jumped the gun. Anyway, just looking for a  
>> way to reduce the verbosity (just as aliases do in a small way).  
>> In my limited experience itql does seem quite a bit more verbose  
>> than sql which maybe isn't a big deal for a developer, but IMO is  
>> an issue for system-admins that need to maintain and manage  
>> production systems.
>>
>> define replace(p, old, new, model)
>>   delete select $s $p $old from $model where $s $p $old from $model;
>>   insert select $s $p $new from $model where $s $p $new into $model;
>> end
>>
>> replace <pred> <old1> <new1> <model>;
>> replace <pred> <old2> <new2> <model>;
>> replace <pred> <old3> <new3> <model>;
>> replace <pred> <old4> <new4> <model>;
>> replace <pred> <old5> <new5> <model>;
>
> That replace function seems a little bizarre - the insert/select is  
> idempotent.  I'm pretty certain you meant:
>
> define replace(p, old, new, model)
>   setautocommit off ;
>   insert select $s ?p ?new from ?model where $s ?p ?old into ?model ;
>   delete select $s ?p ?old from ?model where $s ?p ?old from ?model ;
>   setautocommit on ;
> end

Yes, that would be better.

> and are you sure you want to 'update' _every_ instance with  
> property ?p ?old to ?p ?new

Yes, the customer's marketing has decided that the predicate  
<topaz:organizationType> (a property of a registered user) should no  
longer map to 'University', but to 'University/College'. So all  
subjects whose <topaz:organizationType> is 'University' need to be  
changed to 'University/College'. There are about 8 objects that need  
to be re-mapped.

As I'm beginning to understand things, my understanding now is that  
this is pretty silly to do in the semantic web as it means something  
is changing which is one of HTTP/HTML's fundamental problems. I had  
wondered out-loud to the topaz team if this kind of information  
wasn't best stuffed in a relational database and we could use the  
relational-resolver, but I haven't seen a response to that yet.

> - I must admit I would have thought a more common problem would be
>
> define update(s, p, new, model)
>   setautocommit off ;
>   delete select ?s ?p $old from ?model where ?s ?p $old from ?model ;
>   insert ?s ?p ?new into ?model ;
>   setautocommit on ;
> end
>
> or possibly
>
> define update(pkey, pval, p, new, model)
>   setautocommit off ;
>   delete select $s ?p $old from ?model where $s ?pkey ?pval from ? 
> model ;
>   insert select $s ?p ?new from ?model where $s ?pkey ?pval into ? 
> model ;
>   setautocommit on ;
> end

I don't even think that would work. $old doesn't map to anything in  
the where clause unless you were implying "and ?pval <mulgara:is> $old".

Even so, don't think it would work because ?p == ?pkey and after the  
item is deleted, I won't know what to insert on.

The reason a real update would be nice is because variables ($s in  
this case) would be shared and thus I wouldn't have to insert before  
I delete.  Plus, remembering to turn autocommit off wouldn't be  
important.

> and of course you could also define update(pkey, pval, p, new, old,  
> model) - and that's ultimately the reason why we are discussing a  
> new query language for Mulgara at this point - and no this sort of  
> customisation cannot be provided by a Resolver.
>
> Personally I would love to be working on a new query language for  
> Mulgara, these examples only scratch the surface of what can be  
> offered by adding new abstractions and combinators to an iTql-like  
> core.  For the moment however, my focus has to be on XA2.

Yes, XA2 is important.

Cheers,
Eric




More information about the Mulgara-dev mailing list