Ah, I think I figured out a way to do it...
I still don't know how to get the second SELECT to know anything about
what's in the first one, but I can use a LET block in the 2nd select that
also looks for the @RID. Since there's only one that should get returned
by that I can use first($src) to pull it in the 2nd query:
CREATE EDGE myEdge
FROM
(SELECT FROM data WHERE @RID = #361:0)
TO
(SELECT FROM node
LET $src = (SELECT FROM data WHERE @RID = #361:0)
WHERE Label1 = first($src).Label1 AND Label2 = first($src).Label2)
In my toy problem I have 'nodes':
Label1, Label2
Alpha,A
Alpha,B
Bravo,A
Bravo,B
and 'data':
Label1,Label2,Value
Alpha,A,10
Alpha,A,20
Alpha,B,30
Alpha,B,40
There can be many entries in 'data' that link to my 'node' entries and I
only want to match my edges when both Label1 and Label2 match...
The above CREATE EDGE query generated my edges:
<https://lh3.googleusercontent.com/-IqMrq9Jms_o/WPk1eVqctiI/AAAAAAAAIpU/bQWKdiCSZyARGjkjSYCEwrW3YNV0Ps_lACLcB/s1600/Screen%2BShot%2B2017-04-20%2Bat%2B4.21.22%2BPM.png>
.. but it does feel a bit inefficient since I'm having to execute the SELECT
FROM data WHERE @RID = #361:0 twice for each one. I also will have to
execute this for all of my nodes in data. I'd really like to make this
look something like:
CREATE EDGE
FROM (SELECT FROM data)
TO (SELECT FROM node WHERE node.Label1 = <current data node in 'FROM'>.
Label1 AND node.Label2 = <current data node in 'FROM'>.Label2
FWIW, I can at least move forward with this and just loop over entries in
my data or node classes.
On Thursday, April 20, 2017 at 3:41:24 PM UTC-6, William wrote:
>
> Hi Scott,
>
> I tried this and ran into a couple of things...
>
> It looks like there must be a 'FROM' field in the first SELECT. I'm not
> sure why this is required since my read on the syntax for SELECT
> <https://orientdb.com/docs/2.2/SQL-Query.html> is that the FROM field is
> optional and decoupled from WHERE:
>
> SELECT [ <Projections> ] [ FROM <Target> [ LET <Assignment>* ] ]
> [ WHERE <Condition>* ]
> [ GROUP BY <Field>* ]
>
> That's ok, I just added a "FROM V". This changes my query to this:
>
> CREATE EDGE myEdge
> FROM (SELECT Label1 as NodeLabel1, Label2 AS NodeLabel2 FROM V WHERE @RID
> = #361:0)
> TO (SELECT FROM node WHERE Label1 = NodeLabel1 AND Label2 = NodeLabel2)
>
> It still fails, and the error message isn't very helpful:
>
> 2017-04-20 15:31:43:909 SEVER Internal server error:
> com.orientechnologies.orient.core.exception.OCommandExecutionException: No
> edge has been created because no target vertices
> DB name="testbed-004.orientdb" [ONetworkProtocolHttpDb]
>
>
> I thought I'd try out something with a LET block:
>
> CREATE EDGE myEdge
> FROM (SELECT FROM data LET $temp=(SELECT Label1,Label2 FROM data) WHERE
> @RID = #361:0)
> TO (SELECT FROM node WHERE Label1 = $temp.Label1 AND Label2 = $temp.Label2
> )
>
> But this just gives me the same error.
>
> I'd think there should be a way to have that second SELECT match to fields
> in the records in first vertex, but the solution remains elusive for me.
>
>
>
>
> On Thursday, April 20, 2017 at 3:22:39 AM UTC-6, scott molinari wrote:
>>
>> Can you use aliases?
>>
>> CREATE EDGE myEdge
>> FROM (SELECT Label1 AS NodeLabel1, Label2 AS NodeLabel2 WHERE @RID = #
>> 25:0)
>> TO (SELECT FROM NodeClass2 WHERE Label1 = NodeLabel1 AND Label2 =
>> NodeLabel2)
>>
>> It's just a wild guess and not tested.
>>
>> Scott
>>
>>
>>
--
---
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.