How to Create Edge with Create vertex in OrientDB

173 views Asked by At

I am trying to create an vertex in Purchases class along with its link to Users class vertex. Following example may help you to understand what I am trying to achieve.

Create Edge PurchasedCarts
    FROM
    (CREATE VERTEX Purchases SET guid = "44b4dab7-744a-4f13-ae55-3a563e327de9", accountId = '240059', amount = 44, orderNumber = "1496890", totalItems = 2)
    TO
    (Select @rid from Users)

Above command producing this error

Error parsing query:
Create Edge PurchasedCarts         FROM         (CREATE VERTEX Purchases SET guid = "44b4dab7-744a-4f13-ae55-3a563e327de9", accountId = '240059', amount = 44, orderNumber = "1496890", totalItems = 2)         TO         (Select @rid from Users)
     ^
Encountered " <CREATE> "Create "" at line 1, column 1.
Was expecting one of:
    <SELECT> ...
    <TRAVERSE> ...
    <MATCH> ...
    <INSERT> ...
    <RETURN> ...
    <PROFILE> ...
    <FIND> ...
    <REBUILD> ...
    <OPTIMIZE> ...
    <GRANT> ...
    <REVOKE> ...
    <BEGIN> ...
    <COMMIT> ...
    <ROLLBACK> ...
    <IF> ...
    <SLEEP> ...
    <CONSOLE> ...

    DB name="*****"

Please help me with that or if you can suggest some other better technique I will be very thankful.

1

There are 1 answers

1
Ivan Mainetti On

CREATE VERTEX statement doesn't support that, but you can use the INSERT INTO in addition with UNSAFE keyword:

insert into PurchasedCarts set out=(insert into Purchases SET guid = "44b4dab7-744a-4f13-ae55-3a563e327de9", accountId = '240059', amount = 44, orderNumber = "1496890", totalItems = 2), in=(select from Users) unsafe

PS

about the destination SELECT use select from Users instead of select @rid from Users