I found a way to get the count result using the "first" function and 
accessing the count field.
Unfortunately it doesn't work in combination with the INCREMENT statement.

Using SET instead of INCREMENT works and correctly sets the field "test" to 
the count result:

begin
let cnt = SELECT count(*) from container
UPDATE container SET test = first($cnt).count
commit retry 100

Using INCREMENT instead of SET causes the following error:
java.lang.ClassCastException: 
com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField cannot be 
cast to java.lang.Number

Using ".asInteger()" leads to the same error.
begin
let cnt = SELECT count(*) from container
UPDATE container INCREMENT test = first($cnt).count.asInteger()
commit retry 100


Should I report this as a bug or is there something wrong with the query?

Best regards,
Jonathan

On Sunday, May 17, 2015 at 7:50:53 PM UTC+2, Jonathan Kienzle wrote:
>
> Actually this is what I tried in the first place. Ultimately I would like 
> to execute the query as a transaction.
>
> Unfortunately I get the exact same error when using the code you suggested:
> java.lang.ClassCastException: 
> com.orientechnologies.orient.core.sql.filter.OSQLFilterItemVariable cannot 
> be cast to java.lang.Number
>
> Looking at the error message, I think I would need a way to extract the 
> integer value of the "count" column from the first row of the result set. I 
> couldn't find any information on how to achieve this yet.
>
> On Sunday, May 17, 2015 at 3:20:20 PM UTC+2, Izzet Pembeci wrote:
>>
>> Did you try using the BATCH 
>> <http://orientdb.com/docs/2.0/orientdb.wiki/SQL-batch.html> mode? 
>> Something like this may work:
>>
>> begin
>> let cnt = SELECT count(*) from containerUPDATE container INCREMENT position 
>> = $cntcommit retry 100
>>
>>
>> iZzeT
>>
>> On Saturday, May 16, 2015 at 5:41:00 PM UTC+3, Jonathan Kienzle wrote:
>>>
>>> Hello,
>>>
>>> I'm looking for a way to use the result of a count sub query as the 
>>> argument to an update increment statement.
>>> What I currently have is a query like this:
>>>
>>> UPDATE container INCREMENT position = (SELECT count(*) from container)
>>>
>>> Unfortunately it leads to the following error:
>>> java.lang.ClassCastException: 
>>> com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField cannot be 
>>> cast to java.lang.Number
>>>
>>> I'm using OrientDB 2.0.8.
>>> Any ideas on how I could use a sub query count result inside an 
>>> increment statement?
>>>
>>> Best regards,
>>> Jonathan
>>>
>>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to